sakefox posted on 2008-04-24 23:08:13 #
I didn't see this in the manual so i might have missed it, but is there a easy way to add to a already existing array.
example:
have this array
Array
(
[0] => 1
[1] => 1
)
but now want to add
[3] => 1
to it. is there a easy way to do this or does it have to be broke down and recreated?
The most popular forum posts:
Comments / discussions
Olaf posted on 2008-04-25 04:46:01 #
You mean this?
$somearray = array('0'=>'hello', '1'=>'world');
$somearray[3] = 'cool';
sakefox posted on 2008-04-25 05:04:30 #
I guess i left a lot out in this, that's what i get for posting when i get up lol
Here is what i am trying to do:
have a array that has X amount of info in it (amount is different for each item). but need to be able to add more items to that array later on. The array is going to be stored in a mysql table, but i need the ability to add or remove items to the array.
the only way i had thought about doing it was doing a foreach on the original array stored in the database and the again on the array created from the form and then combining it to one array, but thought there had to be a much easier way
Olaf posted on 2008-04-25 05:28:22 #
Yeah right, in the beginning are very scary, but if you know them a little they are very powerful ;)
Do you need a special array index system?
do you use serialize to store the array in you mysql database?
sakefox posted on 2008-04-25 05:50:30 #
yeah i use serialize to put them in the the database.
yeah arrays are a little intimidating at first, but they get easier. its just trying to add more or take stuff out of the array is where i am having a small snag on
Olaf posted on 2008-04-25 06:53:25 #
A good training is building arrays with multiple array (think about parsing XML)
sakefox posted on 2008-04-25 15:45:16 #
you have a link or info on that?
if i'm going to learn it might as well learn it correctly then off bad way hehe
Olaf posted on 2008-04-25 15:49:18 #
... check the array page from the manual
<?php
$fruits = array (
"fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);
?>
sakefox posted on 2008-04-25 15:57:10 #
bah, i must have over looked that thanks heh