eldan88 Posted April 11, 2013 Share Posted April 11, 2013 Hey, I am new to learning PHP and I am trying to echo out an array using a function, but its just displaying "array" Can someone please tell me what am i doing incorrectly? Thanks! <?php function get_stores() { $store_array = array(); $stores = array('store1','store2'); foreach ($stores as $store_temp) { $store_array[] = $store_temp; } return $store_array; } echo get_stores(); ?> Quote Link to comment Share on other sites More sharing options...
Strider64 Posted April 11, 2013 Share Posted April 11, 2013 (edited) <?php function get_stores() { $stores = array( "First Name" => "Kevin", "Last Name" => "Smith", "Occupation" => "Director" ); foreach ($stores as $key => $value) { echo "key = " . $key . " value = " . $value . "<br />"; } return $stores; } // use print_r instead to see how the array is setup $my_array = get_stores(); print_r($my_array); ?> Edited April 11, 2013 by Strider64 Quote Link to comment Share on other sites More sharing options...
Solution PaulRyan Posted April 11, 2013 Solution Share Posted April 11, 2013 <?PHP function get_stores() { $store_array = array(); $stores = array('store1','store2'); foreach ($stores as $store_temp) { $store_array[] = $store_temp; } return print_r($store_array, TRUE); } echo get_stores(); ?> Quote Link to comment Share on other sites More sharing options...
eldan88 Posted April 11, 2013 Author Share Posted April 11, 2013 <?PHP function get_stores() { $store_array = array(); $stores = array('store1','store2'); foreach ($stores as $store_temp) { $store_array[] = $store_temp; } return print_r($store_array, TRUE); } echo get_stores(); ?> Thanks! 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.