answersLogoWhite

0


Best Answer

Using the function "count".

<?php

$foo = array("John", "Jacob", "Jingleheimer", "Schmidt");

echo count($foo); // <-- outputs the number 4

?>

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you count the number of elements in an array using PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you get the middle number for the turbo c using array?

it depends how you have coded your program as: if you initialized your array (a) by loop from 0 then int lb=0,ub=n-1; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]); if you initialized your array (a) by loop from 1 then int lb=1,ub=n; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]);


Can array size be determined using sizeof operator in c?

Yes. The array name is a reference to the array, so you can use sizeof (name) / sizeof (name[0]) to determine the number of elements. Note that sizeof (name) alone gives the length of the array in bytes.


How you count lentgh of string without using strlen?

Basically in C language string is NULL (0x00) byte ending char array. So in order to find out the length of the string you need to count all elements in array until you reach NULL. But that is what strlen does. There are two links with information about strlen implementation and null-terminated strings.


Why multidimensional array element access using indirection operator?

The number of dimensions is immaterial. All arrays are implemented as a one dimensional array. A multidimensional array is simply an array where every element is itself an array. The only thing actually known about any array is that its name is a reference to the start address. Unlike an ordinary (non-array) variable, the elements in the array do not have names, we can only refer to them by their memory offsets from the start of the array. As such, in order to obtain the values stored at those offsets, we must dereference them. While the subscript operator gives us notational convenience, it's easy to forget that there's actually pointer arithmetic and dereferencing going on behind the scenes.


How do you access and store the elements of array?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int main(void) { int a[10],i;//array declaration clrscr(); printf("\n enter the elements of array"); for(i=0;i&lt;10;i++) scanf("%d",&amp;a[i]); printf("\n the elements you enter into the array"); for(i=0;i&lt;10;i++) printf("%5d",a[i]); getch(); return 0; }

Related questions

Program to count the number of numbers in an array using 8085 microprocessor?

A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program.


What function count elements in an array?

Using the count() method:


The maximum number of records you might want to store in an array is defined as MAX When using 0 based indexing what index will reference the last allocated position of an array of size MAX?

If all elements of the array are in use then the last record is referred to as MAX-1. If you are using a count variable to remember how far into the array you are using then this variable will keep track of the last allocated value in the array.


How do you count the vowels in a string using PHP?

build an array of vowels then do a foreach on the array and then explode the string on the array value and the answer is -1 of the result


How do you get the middle number for the turbo c using array?

it depends how you have coded your program as: if you initialized your array (a) by loop from 0 then int lb=0,ub=n-1; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]); if you initialized your array (a) by loop from 1 then int lb=1,ub=n; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]);


Can array size be determined using sizeof operator in c?

Yes. The array name is a reference to the array, so you can use sizeof (name) / sizeof (name[0]) to determine the number of elements. Note that sizeof (name) alone gives the length of the array in bytes.


Can ragged arrays created by using java?

I assume you mean that you have a number of rows, and that not all rows have the same number of "cells". Yes, in Java a two-dimensional array is implemented as an array of arrays (each item in the top-level array is, in itself, an array); a 3-dimensional array is an array of arrays of arrays, etc.; and there is no rule stating that all secondary (etc.) arrays must have the same number of elements.


How you count lentgh of string without using strlen?

Basically in C language string is NULL (0x00) byte ending char array. So in order to find out the length of the string you need to count all elements in array until you reach NULL. But that is what strlen does. There are two links with information about strlen implementation and null-terminated strings.


Why multidimensional array element access using indirection operator?

The number of dimensions is immaterial. All arrays are implemented as a one dimensional array. A multidimensional array is simply an array where every element is itself an array. The only thing actually known about any array is that its name is a reference to the start address. Unlike an ordinary (non-array) variable, the elements in the array do not have names, we can only refer to them by their memory offsets from the start of the array. As such, in order to obtain the values stored at those offsets, we must dereference them. While the subscript operator gives us notational convenience, it's easy to forget that there's actually pointer arithmetic and dereferencing going on behind the scenes.


How can you get position of number from given some number by using array in c language?

Traverse the array from index 0 until you find the number. Return the index of that number.


How do you access and store the elements of array?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int main(void) { int a[10],i;//array declaration clrscr(); printf("\n enter the elements of array"); for(i=0;i&lt;10;i++) scanf("%d",&amp;a[i]); printf("\n the elements you enter into the array"); for(i=0;i&lt;10;i++) printf("%5d",a[i]); getch(); return 0; }


Give an example where passing an argument by reference would be useful?

If you need to pass an array with the large number of elements the best way to do it is using passing by reference because you don't create a copy of the array. Thus, you save free RAM space.