- Forums
- PHP
- How To Add Values To An Array In Php
This Page Contains information about How To Add Values To An Array In Php By Webune Support in category PHP with 0 Replies. [2049], Last Updated: Mon Jun 24, 2024
Webune Support
Sun Oct 18, 2009
0 Comments
406 Visits
Thanks for visiting Webune Support Forums.
today we are going to show you how its possible to add more elements or values to an array..
lets say i have a array called fruits.
$fruits[0] = 'banana';
$fruits[1] = 'apple';
ok, lets say now i want to add orange and grapes so this is how i would add it
array_push(fruits, 'orange', grapes')
now the array will become:
$fruits[0] = 'banana';
$fruits[1] = 'apple';
$fruits[2] = 'orange';
$fruits[3] = 'grapes';
but if that doesnt work try array_merge() function:
PHP CODE:
<?php
$fruits= 'apple';
$vegetables= array(1 => 'broccoli');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);
?>