0

Hi I have an array that is indexed 0-13 its key valued so each index has an array of its own nested, I want to be able to change the order of it to [0,2,1,3,4,5,7,6,8,10,9,11,13,12]. here is my attempt but it doesn't work at the moment.

var (array)
1   
array
id  1
date modified   2005-01-19 
2   
array
id  2
date modified   2005-01-19

that is the structure of the array I want to change, I want to change the order of the array .

3

2 Answers 2

1

The simplest way to swap the places of the array elements I think would be to make a new array and put elements in it in whichever order you want.

Sign up to request clarification or add additional context in comments.

Comments

0

Something like this will work:

$arr = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$temp = -1;

$temp = $arr[0];
$arr[0] = 0;
$temp = $arr[2];
$arr[1] = $temp;
$temp = $arr[1];
$arr[2] = $temp;
$temp = $arr[3];
$arr[3] = $temp;
$temp = $arr[4];
$arr[4] = $temp;
$temp = $arr[5];
$arr[5] = $temp;
$temp = $arr[7];
$arr[6] = $temp;
$temp = $arr[6];
$arr[7] = $temp;
$temp = $arr[8];
$arr[8] = $temp;
$temp = $arr[10];
$arr[9] = $temp;
$temp = $arr[9];
$arr[10] = $temp;
$temp = $arr[11];
$arr[11] = $temp;
$temp = $arr[13];
$arr[12] = $temp;
$temp = $arr[12];
$arr[13] = $temp;

Ugly but it's what you're asking for.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.