php关联数组内容打印到屏幕

时间:2017-06-27 15:47:38

标签: php arrays

我有一个返回函数内容的函数。我有一个混合了字符串,整数,日期和双打的数组。

my_function(){
 $return_content = '';
 /* Contents of myArray are 
 Category1[0] = [0]; category[0][0] = example1; category[0][1] = '0'; category[0][2] = 2020-01-01; category[0][3] = 'This is example text;
Category2[0] = [0]; category[1][0] = example2; category[1][1] = '25'; category[1][2] = 2021-01-01; category[1][3] = 'This is example text; */

//When i return my array with the below statement it displays the above text.
$return_content .= myArray

//But when i return 
$return_content .= $myArray[0]; /* or */ $return_content .= $myArray[0][1];
// Nothing comes up


return $return_content;


}

我如何挑出我的数据来读取myArray [0]的集合,或者即使我想获得更具体的myArray [0] [1]。

1 个答案:

答案 0 :(得分:1)

这是我认为你需要的。真的,我不知道。=被用于什么。

使用global传递变量。

我不知道获取特定索引的逻辑是什么,因此您需要填写该逻辑......

//This is the assumed structure. 
//If you want help with actuall data make sure to provided clean usable data...
$category = array( 
    ['example1', 0,'2020-01-01','This is example text'],
    ['example2',25,'2021-01-01','This is example text']
);

//Needed the function key word.
//First pass things into a function as a parameter
function my_function($multi_array){
    //Use the param name as the current function scopes variable

    //Not sure why you were using .= just return what you want?
    return $multi_array[0][1];
}

//Need to call the function to make it run
$retValue = my_function($category);

echo $retValue; //With current data outputs 0