Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php为数组的每次迭代分配唯一变量_Php_Arrays_Foreach - Fatal编程技术网

php为数组的每次迭代分配唯一变量

php为数组的每次迭代分配唯一变量,php,arrays,foreach,Php,Arrays,Foreach,我想在foreach循环中为每一组数组分配一个惟一变量 我已经形成了一个阵列 Array ( [0] => Array ( [title] => Mobiles & Accessories ) [1] => Array ( [title] => Mobile Accessories ) [2] => Array ( [title] =&

我想在foreach循环中为每一组数组分配一个惟一变量

我已经形成了一个阵列

Array
(
    [0] => Array
        (
            [title] => Mobiles & Accessories
        )

[1] => Array
    (
        [title] => Mobile Accessories
    )

[2] => Array
    (
        [title] => Cables
    )

)


我希望每个数组集都是唯一的变量

等等,请提供任何帮助

您可能正在寻找“”

有时可以方便地使用变量名。 也就是说,可以动态设置和使用的变量名



foreach迭代的
foreach迭代在哪里?在尝试之后,这些是一些数组,而不是数组!foreach($key=>$values的category_path['subcat']as$key=>$values){谢谢大家。让我重申我的问题-我们正在获取数组中的多个类别路径层次结构,现在是3级到5级的路径,例如在3级场景中“手机和配件、手机配件、电缆”需要连接并放置在变量中,然后插入到列中,现在每个产品的API响应在数组中有几个这样的路径。我们正在尝试在表中插入每个产品的唯一路径。我们知道最多可以有5个路径,因此我们将它们作为5个cat_路径(1-5)要插入的列/属性。Amazon站点有路径。最初我使用foreach以这种方式迭代数组foreach($category_path['categoryPath']作为$key=>$values){print_r($values)}现在我需要在foreach循环中迭代这些数组,以不同的方式存储到Mysql数据库中coloumn@DineshGopal我不明白!!如果你可以访问数组来打印它们,那么你可以访问它们在其他地方也使用它们!!让我重申我的问题-我们正在获取多个hI数组中类别路径的存档,现在是3级到5级的路径,例如在3级场景中“移动设备和附件、移动附件、电缆”需要连接并放置在变量中,然后插入到列中,现在每个产品的API响应在数组中有几个这样的路径。我们正在尝试在表中插入每个产品的唯一路径。我们知道最多可以有5个路径,因此我们将它们作为5个cat_路径(1-5)要插入的列/属性。Amazon站点有路径。@DineshGopal这不是一个重新启动!!这是一个全新的问题,但是,为了澄清问题,您需要提供您迄今为止尝试过的内容,并找出您遇到的问题。我已尝试说明我迄今为止尝试过的内容,我需要帮助连接数组的结果(1-5级)插入到单个变量中,然后我可以将其插入到列中
Array
(
    [0] => Array
        (
            [title] => Computers
        )
[1] => Array
    (
        [title] => TV & Video Accessories
    )

[2] => Array
    (
        [title] => Cables
    )

)
Array
(
    [0] => Array
        (
            [title] => Home Entertainment
        )

[1] => Array
    (
        [title] => Video Players & Accessories
    )

[2] => Array
    (
        [title] => Video Accessories
    )

[3] => Array
    (
        [title] => Cables
    )

)
$a = (
    [0] => Array
        (
            [title] => Mobiles & Accessories
        )
[1] => Array
    (
        [title] => Mobile Accessories
    )

[2] => Array
    (
        [title] => Cables
    )

)

$b = Array
(
    [0] => Array
        (
            [title] => Computers
        )
[1] => Array
    (
        [title] => TV & Video Accessories
    )

[2] => Array
    (
        [title] => Cables
    )

)

$c = Array
(
    [0] => Array
        (
            [title] => Home Entertainment
        )
[1] => Array
    (
        [title] => Video Players & Accessories
    )

[2] => Array
    (
        [title] => Video Accessories
    )

[3] => Array
    (
        [title] => Cables
    )

)
<?php
// your arrays
$arrI = [
    ['title' => 'Mobiles & Accessories'],
    ['title' => 'Mobile Accessories'],
    ['title' => 'Cables']
];
$arrII = [
    ['title' => 'Computers'],
    ['title' => 'TV & Video Accessories'],
    ['title' => 'Cables']
];
$arrIII = [
    ['title' => 'Home Entertainment'],
    ['title' => 'Video Players & Accessories'],
    ['title' => 'Video Accessories'],
    ['title' => 'Cables']
];

// You may access the arrays through the following names
$names = array('a', 'b', 'c');

// The arrays
$arrays = array($arrI, $arrII, $arrIII);

// Now, create variables named after the $names array elements,
// and associate each one with the corresponding array in the $arrays by the defined order.
for($i = 0; $i<count($names); $i++)
    $$names[$i] = $arrays[$i];

// Now, you can access the arrays using their new names!
echo "<pre>";
print_r($a);
echo "<hr>";
print_r($b);
echo "<hr>";
print_r($c);
echo "</pre>";
?>