Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.