如何打印数组值?

时间:2022-03-27 01:51:58

I have a value from the database:

我有一个来自数据库的值:

 $rows = array();
  foreach($results as $result)
  {
    $rows[] = array(
        $result->fe_id,
        $result->empcode,
        $result->empname,
        $result->empphoto,
      );
      }

and for another function

和另一个函数

function theme_form_example_function($variables)
{
$output ="<h2><pre>".print_r($variables)."</pre></h2>";
return $output;

}

Its give me the output like

它给出了输出。

Array (
  [rows] =>
  Array ( 
    [0] => 
    Array ( 
      [0] => 1 
      [1] => 12 
      [2] => sim
      [3] => dawn-landscape-mountains-nature-large.jpg
    ) 
    [1] => 
    Array ( 
      [0] => 2 
      [1] => EMP13 
      [2] => simnav 
      [3] => download-nature-wallpaper-23.jpg
    ) 
  ) 
  [theme_hook_original] => form_example_function
)

I want to print the output as:

我想打印输出为:

Empcode: 12 EmpName: Sim Emphot: dawn-landscape-mountains-nature-large.jpg 

and in the second row:

在第二行:

Empcode: EMP13 EmpName: Simnav Emphot: download-nature-wallpaper-23.jpg

How can I use the above array to achieve this output?

如何使用上面的数组来实现这个输出?

1 个解决方案

#1


0  

You can do:

你能做什么:

function theme_form_example_function($variables)
{
    $output = '';

    foreach($variables['rows'] as $row) {

        $output .= "Empcode: " . (isset($row[1]) ? $row[1] : "--") . " ";
        $output .= "EmpName: " . (isset($row[2]) ? $row[2] : "--") . " ";
        $output .= "Emphot: " . (isset($row[3]) ? $row[3] : "--") . "<br>";     
    }

    return $output;
}

#1


0  

You can do:

你能做什么:

function theme_form_example_function($variables)
{
    $output = '';

    foreach($variables['rows'] as $row) {

        $output .= "Empcode: " . (isset($row[1]) ? $row[1] : "--") . " ";
        $output .= "EmpName: " . (isset($row[2]) ? $row[2] : "--") . " ";
        $output .= "Emphot: " . (isset($row[3]) ? $row[3] : "--") . "<br>";     
    }

    return $output;
}