terencepires
asked on
Find value in array, then add value after that key
Hi there,
i'm having a little problem on a script here :
I have to
- find a value recursively inside an array (done)
- then add data right after the value i just found in the array (this is why i need help)
I could use array_push, but that would put data at the end of the array, i want it be put right after the data, shifting down all following values indexes
any leads ?
Cheers,
Terence
i'm having a little problem on a script here :
I have to
- find a value recursively inside an array (done)
- then add data right after the value i just found in the array (this is why i need help)
I could use array_push, but that would put data at the end of the array, i want it be put right after the data, shifting down all following values indexes
any leads ?
Cheers,
Terence
Why not append the key and then sort the array?
$myArray[] = 'E';
sort($myArray);
Alternatively see code
$myArray[] = 'E';
sort($myArray);
Alternatively see code
Why not append the key and then sort the array?
$myArray[] = 'E';
sort($myArray);
Alternatively
$newArray = array();
$insertElement = 'E';
foreach($myArray as $v)
{
if (stricmp($v, $insertElement) > 0)) $newArray[] = $insertElement;
$newArray[] = $v;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks !
Open in new window