Hi,
My question has two parts. The first is built on the assumption of deleting an element.
The following code will describe clearly what I mean.
//Decalare the array $arr[]
$arr[] = "val1";
$arr[] = "val2";
$arr[] = "val3";
$arr[] = "val4";
//deleting the second element using unset() construct
unset($arr[1]);
After this point, if we use list() each() expretion to get elements of $arr, the print out would be
as follows,
0 val1
2 val3
3 val4
While if we use for looping using count($arr), the print out would be as:
0 val1
1
2 val3
What I want to have is making the print out to be :
0 val1
1 val3
2 val4
In other word, I don't want $arr[1], which reffer to the deleted second element, to have no value
or to be null.
The second part of my question is:
How to Exchange values of elements internally. i.e,
0 val4
1 val3
2 val2
4 val1
In other word How to invert the order of elements?
Is there a built in PHP function(s) able to do that?
🙂