learningPHP1 Posted November 28, 2012 Share Posted November 28, 2012 Hello everybody, Unable to output from array. whats wrong with the foreach loop?????? index.php $testdata = $classone->sendError(); echo "<br /> my value==>: ".$testdata[0][0]; <== works foreach ($testdata as $key => $value) <== Not working echo $key . '=>' . $value. '<br />'; results from var_dump($testdata); array(2) { [0]=> array(1) { [0]=> string(29) "First name must not be empty!" } [1]=> array(1) { [0]=> string(28) "Last name must not be empty!" } } my value==>: First name must not be empty! -------------------------------------------- the following class/function called from index.php: public function sendError() { if(classErray) {return $this->classError; } } Quote Link to comment https://forums.phpfreaks.com/topic/271278-not-able-to-output-values-from-array/ Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2012 Share Posted November 28, 2012 (edited) You have a multidimensional array there. It will help you see what the structure actually if you do this: echo '<pre>'; print_r($testdata); echo '</pre>'; Edited November 28, 2012 by Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/271278-not-able-to-output-values-from-array/#findComment-1395783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.