Jump to content

Need help echoing out an array using a function


eldan88

Recommended Posts

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();



?>


<?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);



?>

 

 

<?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();

?>
<?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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.