2017-06-27 5 views
1

私は関数内の内容を返す関数を持っています。私は、文字列、intereger、日付、および倍精度の混合配列を持っています。php画面への連想配列内容の印刷

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]。

+0

このコマンドは '$のreturn_content見当がつかない= $ MyArrayという;'何も印刷されません'$ return_content'を' $ myArray [0] 'に連結し、その値で' $ return_content'を設定します。 '$ return_content = $ return_contentの略です。 $ myArray [0]; ' – nerdlyist

+2

あなたは何をやっているのか、どこに問題があるのか​​、どう見ているのか分かりません。 – nerdlyist

+0

自分のコードを編集して、返品方法を確認することができます – jumpman8947

答えて

1

ここに私が必要と考えるものがあります。本当に私は。=が何のために使われているのか分かりません。

グローバルを使用して変数を渡します。

私は何ロジックはあなたがそのロジックに記入する必要がありますので、特定のインデックスを取得することです...

//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