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

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 end of an array and know how large the array is?


If you want to add an element to an array you can always just use:
$arrayname[] = "$value";

However, if you want to know how many entries are in the array once you've done so, then you can get at that value simply by using the array_push function, like so:


<?php

$values 
= array("I","Like","Sentences","That","Don't");
$newelement array_push($values,"Finish");
echo 
"There are now $newelement elements in the array:\n";
print_r($values);
?>


This prints out the following to the screen:


There are now 6 elements in the array:
Array
(
[0] => I
[1] => Like
[2] => Sentences
[3] => That
[4] => Don't
[5] => Finish
)



ASK A QUESTION

More arrays PHP Questions

Translation Composition Nationalism European Grammar Arabic Poetry Prose ******************************* I want an array equation that helps me to calculate some of varibles unspecific

hi, i am querying the DB as follows: $result=mysql_query("SELECT name,items FROM mytable WHERE user_id='$id'"); now,i want to create an array to insert the values that are as a result of this query e'g let's say this is the resultant data: n

How can I display values in a two dimensional array?

I have an array of numbers and many repeat, how to list all items in order of maximum occurence?

How do you remove duplicate values from an array?



Custom Search