How do I add to the beginning of an array and find the
number of elements in it?
Answer Posted / jude jeevanraj.p
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
)
| Is This Answer Correct ? | 8 Yes | 0 No |
Post New Answer View All Answers
How can you encrypt password using php?
Applications written to provide a GUI shell for Unix and Linux are called
Which is better python or php?
What good is polymorphism?
Explain include(), include_once, require() and require_once?
What is php artisan tinker?
How many types of php frameworks are there?
How to check whether a number is prime or not?
How can we submit form without a submit button?
Explain what is the difference between session and cookie?
How can we destroy the cookie in php?
Suppose your zend engine supports the mode ?> Then how can you configure your php zend engine to support Mode ?
What are helpers in php?
Does https prevent csrf?
> symbol is used to redirect the output of a command. State Whether True or False?