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(); ?> Link to comment https://forums.phpfreaks.com/topic/276834-need-help-echoing-out-an-array-using-a-function/ Share on other sites More sharing options...
Strider64 Posted April 11, 2013 Share Posted April 11, 2013 <?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); ?> Link to comment https://forums.phpfreaks.com/topic/276834-need-help-echoing-out-an-array-using-a-function/#findComment-1424163 Share on other sites More sharing options...
PaulRyan Posted April 11, 2013 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(); ?> Link to comment https://forums.phpfreaks.com/topic/276834-need-help-echoing-out-an-array-using-a-function/#findComment-1424164 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! Link to comment https://forums.phpfreaks.com/topic/276834-need-help-echoing-out-an-array-using-a-function/#findComment-1424172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.