PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I add to the beginning of an array and find the number of elements in it?


To do this, you will want to use the array_unshift function which works like this.

<?php
$values 
= array(2,3,4,5,6,7,8,9,10);
$elements array_unshift($values,1);

echo 
"Number of elements: $elements \n\n";
print_r($values);
?>


Here's the output:

Number of elements: 10

Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)



Comment on this Question and Answer >>>

ASK A QUESTION

More arrays PHP Questions

How can I create an array of the letters of the alphabet?

How can I check if a value is already in an array?

I have an array of a hundred or so lines, each line has data with "|" separated values. I need to scan through this array, and select the line whose first 5 characters matches a text string. Any ideas or questions?

How do you remove duplicate values from an array?

Hi. i have a music samples website. in one table, id like a different sample to appear every time the page is refreshed. how do i acheve this? how can i alterate and retrieve these bloody mp3's? surely i can use a PHP script? thankyou



Custom Search