corbeeresearch Posted September 21, 2010 Share Posted September 21, 2010 Hi, I have session data like this: $_SESSION[‘data’][‘basic_premium’] $_SESSION[‘data’][‘gross_premium’] $_SESSION[‘data’][‘net_premium’] each second parameter is made of arrays I tried to extract it using: foreach ($_SESSION['data'] as $row) { echo $row; } but I get Array0.125ArrayArrayArrayArrayArrayArrayArrayArrayArray1927.51850.423.13ArrayArrayArray50664.525 . Where did I went wrong? Thanks Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2010 Share Posted September 21, 2010 Put this in your script after the array has been built, and paste in the output. Also, the quotes in your first code block are non-standard 'curly-quotes' or 'smart' quotes or something along those lines, and will cause you headaches eventually. echo '<pre>'; print_r($_SESSION['data']); echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
corbeeresearch Posted September 21, 2010 Author Share Posted September 21, 2010 I see, here is the output: [basic_premium] => Array ( [0] => 14000 [1] => 14490 ) [gross_premium] => Array ( [0] => 15430 [1] => 15420 ) [net_premium] => Array ( [0] => 25233.495 [1] => 25431.03 ) Quote Link to comment Share on other sites More sharing options...
corbeeresearch Posted September 21, 2010 Author Share Posted September 21, 2010 I actually needed to extract each individuals, unfortunately when I do foreach ($_SESSION['data'] as $row) { echo $row['basic_premium']; } I get error it says Message: Undefined index: basic_premium Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2010 Share Posted September 21, 2010 foreach ($_SESSION['data']['basic_premium'] as $row) { echo $row; } Will echo all of the values in basic_premium elements, but I suspect that isn't what you really want to do . . . Quote Link to comment Share on other sites More sharing options...
corbeeresearch Posted September 21, 2010 Author Share Posted September 21, 2010 yeah, that's not what I wanted to do. I needed it to loop the three data all at once. Are there any way to achieve this? Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 21, 2010 Share Posted September 21, 2010 A nested foreach loop? foreach($_SESSION['data'] as $key => $arr) { if(is_array($arr)) { foreach($arr as $amount) { echo $key . ': ' . $amount . '<br />'; } } } Quote Link to comment 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.