I want to store images in an array on every click before sending the data for database injection.
Below is my dummy test, but I can’t get my head around to increase/ store the images array,
<?php
function add_image($image = array())
{
# Loop and rename the table.
foreach($image as $key => $item)
{
$images[] = array(
'image_id' => $image[$key]['image_id'],
'image_title' => $image[$key]['image_title']
);
}
return $images;
}
if($_REQUEST['add'] == '1')
{
$image = array(
array(
'image_id' => 1,
'image_title' => 'test 1'
)
);
$images = add_image($image);
var_dump($images);
}
if($_REQUEST['add'] == '2')
{
$image = array(
array(
'image_id' => 2,
'image_title' => 'test 2'
)
);
$images = add_image($image);
var_dump($images);
}
?>
<a href="array_session.php?add=1">add 1</a>
<a href="array_session.php?add=2">add 2</a>
I will get a fresh image array on each click like this,
array
0 =>
array
'image_id' => int 1
'image_title' => string 'test 1' (length=6)
or,
array
0 =>
array
'image_id' => int 2
'image_title' => string 'test 2' (length=6)
instead of
array
0 =>
array
'image_id' => int 1
'image_title' => string 'test 1' (length=6)
1 =>
array
'image_id' => int 2
'image_title' => string 'test 2' (length=6)
Is it to do with session that I should be using?
PHP session is really easy to use, you should start by reading documentation.
Here is an example :
After that, you just have to use $_SESSION[‘images’] to store your images data.