Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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 CodeIgniter_Php_Mysql_Arrays_Codeigniter - Fatal编程技术网

数组按键分组PHP CodeIgniter

数组按键分组PHP CodeIgniter,php,mysql,arrays,codeigniter,Php,Mysql,Arrays,Codeigniter,我的PHP代码有以下响应 Array ( [customer] => 402 [carat] => Array ( [0] => 6 [1] => 5 ) [units] => Array ( [0] => grams [1] => dwt [2] => dwt ) [weight] => Array (

我的PHP代码有以下响应

Array
(
[customer] => 402
[carat] => Array
    (
        [0] => 6
        [1] => 5
    )

[units] => Array
    (
        [0] => grams
        [1] => dwt
        [2] => dwt
    )

[weight] => Array
    (
        [0] => 5
        [1] => 3
        [2] => 6
    )

[our_payout] => Array
    (
        [0] => 15
        [1] => 9
        [2] => 60
    )

[sale_payout] => Array
    (
        [0] => 18
        [1] => 12
        [2] => 180
    )

[hidden_carat] => Array
    (
        [0] => 6
        [1] => 5
        [2] =>
    )

[hidden_unit] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 2
    )

[carat_scale_price] => Array
    (
        [0] =>
        [1] =>
        [2] =>
    )

[sales_id] => Array
    (
        [0] =>
        [1] =>
        [2] =>
    )

[currency_rate_id] => Array
    (
        [0] =>
        [1] =>
        [2] =>
    )

[gold_price_id] => Array
    (
        [0] =>
        [1] =>
        [2] =>
    )

[taget_percentage] =>
[reference] => 0
[notes] =>
[unit] => 0
[customer_id] => 402
[total_items] => 2
[submit] =>
)

我想加入
示例[0]=>grams
[0]=>5[0]=>16
等等。我该怎么做呢?

我和史蒂夫在一起,我不太确定你要什么。看起来你想转置那个矩阵,但只对一些键?假设上面的原始数组位于变量$arr中,则以下内容可能会满足您的需要:

$lineItems = array();
$i = 0;
$allLineItemsHaveI = true;

while($allLineItemsHaveI) {
   $lineItems[$i] = array();
   foreach($arr as $key => $subArr) {
      if(array_key_exists($i, $subArr)) {
         $lineItems[$i][$key] = $subArr[$i];
      } else {
         $allLineItemsHaveI = false;
      }
   } 

   $i++;
}    

array_pop($lineItems);
这是输出:

Array
(
    [0] => Array
        (
            [carat] => 6
            [units] => grams
            [weight] => 5
            [our_payout] => 15
            [sale_payout] => 18
            [hidden_carat] => 6
        )

    [1] => Array
        (
            [carat] => 5
            [units] => dwt
            [weight] => 3
            [our_payout] => 9
            [sale_payout] => 12
            [hidden_carat] => 5
        )

)

另外,请检查以下内容:

我们不完全确定您的问题是什么?你想做弦乐表演吗?