So, I have this array of objects called $_SESSION['cart']
, which gets data from front-end and store as an array of objects.
foreach($_SESSION['cart'] as $value){
$temp = (array) $value;
for($i = 0; $i < count($temp); $i++){
echo $temp['name'] . "<< - name <br>";
echo $temp['price'] . "<< - price<br>";
}
}
And since I want to convert each of the object into an array, I will loop through it and store a new array in $temp
where each key and value will be outputted. I am amatuer and I have got pretty messed up in my head right now since I have been trying this for a couple of hours.
However, the output of the above code seems like
c1<< - name
1<< - price
c1<< - name
1<< - price
c1<< - name
1<< - price
c1<< - name
1<< - price
m1<< - name
1<< - price
m1<< - name
1<< - price
m1<< - name
1<< - price
m1<< - name
1<< - price
which does not seem like a proper array for me. All the information I have is the name and I want to unset a sub-array that is related to that name. I only have two objects in it, but I have four keys in there and I think that's the reason why the output acts like there is 8 object.
So that is what I tried!
What I want to do is to unset an object related to a specific name.
$_SESSION['cart']
is an array, and everyitem within that is an object. If I loop and json_encode that $_SESSION['cart'], I would get a JSON in the console.