0
$products = Array ( [products] => Array ( [0] => 12,11,10 [1] => 16,15,14 
[2] => 600,103,20 ) );
$info = implode(",",$_POST['product']);
$info1 = implode(",",$_POST['product_weight']);
$info2 = implode(",",$_POST['quantity']);

admin_orderrequest_add($params,$products,$obj);

foreach($products as $k=>$v)
{
  echo $product_id = $v[0];
  echo $product_weight_id = $v[1];
  echo $product_quantity = $v[2];
  $weight_info = admin_get_weight_info($product_weight_id,$obj);
}

now output first time:
12,10,11
16,15,14
600,103,20

required output : 1st time
12
16
600

2nd time all second value of array
3rd time all 3rd value of array

2 Answers2

2

array_column() is used to generate a new array by the same key. So you can use array_column()

$products = [[12,11,10], [16,15,14], [600,103,20]];

echo 'First column' . PHP_EOL;
echo implode(PHP_EOL, array_column($products, 0));
echo PHP_EOL . 'Second column' . PHP_EOL;;
echo implode(PHP_EOL, array_column($products, 1));
echo PHP_EOL . 'Third column' . PHP_EOL;;
echo implode(PHP_EOL, array_column($products, 2));

Demo

MH2K9
  • 11,951
  • 7
  • 32
  • 49
2

Answer posted by MH2K9 works, you can also use the below code if you want to loop through them

$products = [[12,11,10], [16,15,14], [600,103,20]];

if(!empty($products) && isset($products[0])){
    $product_ids = $products[0];
    $product_weight_ids = $products[1];
    $product_quantities = $products[2];

    foreach($product_ids as $key=>$v)
    {
        echo $product_id = $v; echo "<br/>";
        echo $product_weight_id = $product_weight_ids[$key];echo "<br/>";
        echo $product_quantity = $product_quantities[$key];echo "<br/>";
        echo "<br/>";echo "<br/>";echo "<br/>";
        $weight_info = admin_get_weight_info($product_weight_id,$obj);
    }
}

output:

12 16 600

11 15 103

10 14 20

Sameer
  • 361
  • 1
  • 5
  • Hi Bro product array value is $_POST multiple value: $info = implode(",",$_POST['product']); // multiple value $info1 = implode(",",$_POST['product_weight']); // multiple value $info2 = implode(",",$_POST['quantity']); // multiple value – Jayesh Naghera Aug 07 '19 at 13:22
  • Can you be more clear please and why are you using implode, as it is an array you can loop through it – Sameer Aug 08 '19 at 06:28