Yash
Yash

Reputation: 181

How to store two different array's in code igniter cart?

Array
(
    [0] => Array
        (
            [0] => round
            [1] => EX
            [2] => D
            [3] => 3.6
            [4] => IF
            [5] => IGI
            [6] => G
            [7] => G
            [8] => id01
            [9] => FNT
            [10] => 0.8
            [11] => 47
            [12] => xy01
            [13] => india
        )

    [1] => Array
        (
            [0] => round
            [1] => EX
            [2] => D
            [3] => 3.6
            [4] => IF
            [5] => IGI
            [6] => G
            [7] => G
            [8] => id01
            [9] => FNT
            [10] => 0.8
            [11] => 47
            [12] => xy01
            [13] => india
        )

)
Array
(
    [0] => 150
    [1] => 150
)

This Two Array's I Got When I Click Update Cart Button In Codeigniter Cart... In This Two Arrays First Array Is Description About Two Different Product And Second Array Is The Price Of That Two Products...First Price Is For First Product And Second Price Is For Second Product...

now i want to store this two products in cart one by one...i mean at first, first product is stored in cart with respective price and then second product with price..

And i want to store this array in particular array index..

This is the index of the array..

shape
cut
color
carat
clarity
lab
polish
symmetry
stone_id
fluorescence
lwratio
depth
cert_no
location
price

First Product with price store in this array and then in cart...likewise second..

Upvotes: 2

Views: 162

Answers (2)

Ashu
Ashu

Reputation: 1320

If you want to make a single array with description & price then go with below code...

$final_array=array();
for($i=0;$i<count($description_array);$i++)
{
  $final_description=$description_array[$i];
  array_push($final_description,$price_array[$i]); //here we push the price into description array
  array_push($final_array,$final_description);
}

print_r($final_array);

Upvotes: 0

jitendrapurohit
jitendrapurohit

Reputation: 9675

First, add the price to the first array. Then use array_combine() to apply the index as keys - Something like-

foreach ($array1 as $key => &$val) {
  $val[] = $array2[$key];
  //$index is array of indexes mentioned.
  $newArr[] = array_combine($index, $val);
}

var_dump($newArr);

Upvotes: 1

Related Questions