Associate
hey guys,
long story short I have this string
It's a mutli array that i have flattened. This will get bigger in time so the below needs to be automated on any scale.
I'd like to loop though it creating a variable for each instance inbetween [..].
This is what i have so far..
it returns the following;
Can anyone see where I have gone wrong??
I'm quite new to php and any help will be greatly received!
Thanks all
Blastman
long story short I have this string
Code:
[[ Pooh , 2009 , 12 , 12 ],[ Mavis , 2010 , 10 , 31 ],[ Mk1 , 2010 , 6 , 1 ],[ Pooh , 2009 , 12 , 31 ],[ MK1 , 2010 , 2 , 29 ]]
It's a mutli array that i have flattened. This will get bigger in time so the below needs to be automated on any scale.
I'd like to loop though it creating a variable for each instance inbetween [..].
This is what i have so far..
Code:
//Setting counter and book variable for bookings name
$x = 1;
$book = "book";
//Setting first starting point
$start = strpos($bookings, "[", 0);
//while x is less than num_of_bookings create a varaible for each booking with all details inside from string (bookings)
while ($x <= $num_of_bookings){
$end = strpos($bookings, "]", $start);
echo ("<br>---" . $x . "--- start =" . $start . " end =" . $end);
${$book . $x} = substr($bookings, $start, $end);
$start = $end;
$x++;
}
//echoing for testing
echo ("<br>" . $x);
//echoing for testing
echo "<br><br>";
echo "-----";
echo "<br>";
echo $book1;
echo "<br>";
echo $book2;
echo "<br>";
echo $book3;
echo "<br>";
echo $book4;
echo "<br>";
echo $book5;
echo "<br>";
echo $book6;
echo "<br>";
echo "-----";
it returns the following;
Code:
-----
[[ Pooh , 2009 , 12 , 12
],[ Mavis , 2010 , 10 , 3
],[ Mavis , 2010 , 10 , 3
],[ Mavis , 2010 , 10 , 3
],[ Mavis , 2010 , 10 , 3
],[ Mavis , 2010 , 10 , 3
-----
Can anyone see where I have gone wrong??
I'm quite new to php and any help will be greatly received!
Thanks all
Blastman