开发者

php How to display values from an array into a li?

开发者 https://www.devze.com 2023-02-28 08:51 出处:网络
i have a multi-dimensional array like this: Array ( [5432980] => Array ( [0] => 223 [entry_id] => 开发者_StackOverflow223

i have a multi-dimensional array like this:

Array
(
[5432980] => Array
    (
        [0] => 223
        [entry_id] => 开发者_StackOverflow223
        [1] => 138
        [elo_score] => 138
        [2] => 38
        [hits] => 38
    )

[2712949] => Array
    (
        [0] => 701
        [entry_id] => 701
        [1] => 128
        [elo_score] => 128
        [2] => 28
        [hits] => 28
    )
)

i get the array from here $leader_array = fns_elo_search_entries();

i an trying to get each array ([5432980], [2712949]) in a li using foreach

something like this

<ul>
<li>load here the information from `[5432980]`</li>
<li>load here the information from `[2712949]`</li>
</ul>

i know that i need to use two foreach statements because is an multi-dimensional array any ideas? thanks


echo '<ul>';
foreach($array as $valueArray)
{
   echo '<li>';
   foreach($valueArray as $value)
   {
     echo $value;
   }
   echo '</li>';
}
echo '</ul>';


Alternate way, comma separated:

foreach ($arr as $key => $values):

    echo "<li>{$key}: ".implode(', ', $values)."</li>";

endforeach;

load here the information from [5432980] is not too clear as far as what you want and how you want it formatted, so I simply gave an alternative to 2 foreach loops.

As mentioned in the comments, you can just access the keys directly.

foreach ($arr as $key => $values):

    echo "<li>Score: ".$values['elo_score']."</li>";//etc.

endforeach;


<ul>
<?php
foreach($arrs as $arr){
  echo "<li>";
  foreach($arr as $a){
    echo "value: " . $a;
  }
 echo "</li>";
}

?>

</ul>

This is just basic formatting.


echo "<ul>";
array_walk($arr, 'ulli');
echo "</ul>";
function ulli(&$value, $index){
    if(is_array($value)){
        echo "<ul>";
        array_walk($value, 'ulli');
        echo "</ul>";
    }else{
        echo '<li>'.$value.'</li>';
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消