Jump to content

[SOLVED] echo ing multidimensional arrays


emtec

Recommended Posts

i'm trying to echo values from an multidimensional error in a loop

 

array:

$error = array();
array_push($error, array (icon => "error.png",text => ADMINPASSERROR ));

 

echo:

if (!empty($error)){
echo "<div class='error_message'>";
$nr = count($error);
for ($row = 0; $row < $nr; $row++)
{	
echo"<p><img src='images/icons/".$error['icon']."' width='16' height='16' /> ".$error['text']."</p>";
} 
//close error box
echo "</div><!-- end error_message -->";
}

 

it just shows nothing, can any1 tell me what i'm doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/
Share on other sites

Not sure but wouldnt it be:

 

<?php
if (!empty($error)){
echo "<div class='error_message'>";
$nr = count($error);
for ($row = 0; $row < $nr; $row++)
{   
   echo"<p><img src='images/icons/".$error[$nr]['icon']."' width='16' height='16' /> ".$error[$nr]['text']."</p>";
}
//close error box
echo "</div><!-- end error_message -->";
}
?>

you're pushing an array into a declared array.  As the title of your thread implies, it's a multi-dim array.  But you're only echoing it out as if it's a single-dim array.  You should be doing for instance:

 

$error[0]['icon']

 

premiso had it right, but he used the wrong var for the first level.  Should have been $row not $nr

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.