array-push

how do I keep a certain number of elements in an array?

Hi how do I keep a certain number of elements in an array? function test($var) { if(is_array($_SESSION['myarray']) { array_push($_SESSION['myarray'], $var); } } test("hello"); I just want to keep 10 elements in array $a. So when I call test($var) .. it should push this value to array but keep the number to 10 by remo...

Can I use array_push on a SESSION array in php?

I have an array that I want on multiple pages, so I made it a SESSION array. I want to add a series of names and then on another page, I want to be able to use a foreach loop to echo out all the names in that array. This is the session: $_SESSION['names'] I want to add a series of names to that array using array_push like this: arra...

array_push key=>value , how can do it?

Hi , all I want to push key and value in array , but I can't $con = mysqli_connect('localhost','root','','wp') or die (mysqli_error('Error:')); $query = mysqli_query($con,'set names utf8')or die (mysql_error()); $qy = mysqli_query($con,"SELECT ID,post_title FROM wp_posts WHERE post_type='page' AND post_status='publish'")or die (mysql...

Array Push with key value

How do you add an value with an => $key into an array, for example: $images = array(); array_push($images, $_FILES['file']['tmp_name'] => $_FILES['file']['name']); So the array would be like: array('temporary_file_name' => 'file_name.zip'); But my IDE says it's invalid and would not work. ...

ooPHP - How do I create an array of objects from an associative array?

Hi all, I'm not sure if this is even possible after trying to figure it out for hours but here goes... I have an class, UserPicture, which has properties for filename, filetype, created etc. (i.e. it doesn't store the actual picture as a blob, rather references it by using $filename.$filetype). I want to be able to have a page that dis...