emtec Posted December 19, 2008 Share Posted December 19, 2008 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 More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 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 -->"; } ?> Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719332 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 thx for the help, but it isent working, showing still nothing Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719333 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 Is $error being populated on the same page? Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719334 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 in an include, the array works on that page, have tested that Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719335 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 if any1 wants i can post my full code but dont think thats needed though Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719339 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 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 Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719340 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 thx a lot, that did it was my first time using multi-dim arrays ^^ Link to comment https://forums.phpfreaks.com/topic/137622-solved-echo-ing-multidimensional-arrays/#findComment-719341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.