John Davidson

PHP use Array of indexes as Array index

0 comments
Message:


I have an array of indexes and a value to insert.


$indexes = [0,1,4];
$value_to_insert = 820;
$array_to_fill = [];

How can i use the indexes array like this to insert a value:


$array_to_fill[$indexes] = 820;

To produce a nested array of this style:


$array_tree = [
"0" => [
"1" => [
"4" => 820
]
]
]

i tried using pointers to maybe save the location of the array but that only saves a chunk of the array not the position. I have spent too many hours on this and help would be very much appreciated.



My Answer:
[
0 => 820,
1 => 820,
4 => 820
]

Rate this post

5 of 5 based on 5320 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us