在变量

时间:2016-12-21 18:09:15

标签: php arrays

$content="The value of this variable is {$array['1']['value']}" 

对于不同的多维数组值,我必须在许多段落中多次执行此操作。似乎无法在线找到答案。谢谢!

编辑:

我有一个多维数组当前正在发布到我发布数组的页面,所以我想说我想得到当前的值:  $阵列[' 1'] [' thisvalue']

在同一个文件中,我有一个变量$ content: 我使用$ content来存储文章中的文本。在$ content变量的这篇文章中,我有一些空白,我将使用数组值($ array [' 1'] [' thisvalue']) 填写。例如:

$ content ="我的名字是_____,我的身高是____"

$ array [' 1'] [' thisvalue']将包含我的姓名和$ array [' 2'] [' thisvalue' ;]将包含我的身高

所以

$ content ="我的名字是 $ array [' 1'] [' thisvalue'] ,我的身高是 $阵列[' 2'] [' thisvalue'] "

然后在填写所有空白的最后

file_put_contents($file, $content);

$ file是我在另一个目录中生成的文件,我将内容放入文件中。

我的问题是:

如何使用多维数组填充文章的空白,以便在写入此单独的$ file文件时,它将使用正确的值进行扩展。

1 个答案:

答案 0 :(得分:0)

foreach或任何其他类型的循环将为您完成工作。

即。 :

数组:

print_r($arr);
Array
(
    [0] => Array
        (
            [some_key] => Something
        )

    [1] => Array
        (
            [some_key] => Another Something
        )

    [2] => Array
        (
            [some_key] => Again Another Something
        )

    [3] => Array
        (
            [some_key] => Something Else
        )

    [4] => Array
        (
            [some_key] => Need more imagination...
        )

)

循环:

foreach ($arr as $item) {
    echo $item['some_key'] . "\n";
}

输出

Something
Another Something
Again Another Something
Something Else
Need more imagination...