<?php
$keys = ["1","2","3","4-1","99","1","2","3","4-1","4-2","4-3","99","1","2","3","4-1","4-2","99"];
$values = ["a","b","c","d","x","a1","b1","c1","d1","e","g","x","a2","b2","c2","d2","e","x"];
$new_array = array();
$split_at = "99";
$i = 0;
foreach ($keys as $key => $value) {
$new_array[$i][$value] =$values[$key];
if($split_at == $value){
$i++;
}
}
print_r($new_array);
- Output for 7.0.0 - 7.0.23, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- Array
(
[0] => Array
(
[1] => a
[2] => b
[3] => c
[4-1] => d
[99] => x
)
[1] => Array
(
[1] => a1
[2] => b1
[3] => c1
[4-1] => d1
[4-2] => e
[4-3] => g
[99] => x
)
[2] => Array
(
[1] => a2
[2] => b2
[3] => c2
[4-1] => d2
[4-2] => e
[99] => x
)
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[0] => Array
(
[1] => a
[2] => b
[3] => c
[4-1] => d
[99] => x
)
[1] => Array
(
[1] => a1
[2] => b1
[3] => c1
[4-1] => d1
[4-2] => e
[4-3] => g
[99] => x
)
[2] => Array
(
[1] => a2
[2] => b2
[3] => c2
[4-1] => d2
[4-2] => e
[99] => x
)
)
preferences:
220.79 ms | 403 KiB | 223 Q