answersLogoWhite

0

To empty an array in PHP you need to use the unset function like shown below:

<?php

$array = array('hello', 'hi', 'weee');

unset($array); // empty

?>

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Math & Arithmetic

How do you find the size of an array in PHP?

To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?&gt;


How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?&gt;


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 can you check if a value is already in an array in PHP?

To check if a value is already in an array you will need to use the in_array function like shown below! &lt;?php $values = array("pizza","hello","cheese","fred"); $newvalue = "hello"; if (in_array($newvalue, $values)) { echo "$newvalue is already in the array!"; } ?&gt;


How do you merge and sort an array using PHP?

To merge and sort an array in PHP you need to use the array_merge() and sort() functions like shown in the example below: &lt;?php $array1 = array(1, 5, 3, 9, 7); $array2 = array(8, 2, 6, 4, 0); // merge the arrays $merge = array_merge($array1, $array2); // 1, 5, 3, 9, 7, 8, 2, 6, 4, 0 // sort the array sort($merge); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ?&gt;

Related Questions

How do you find the size of an array in PHP?

To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?&gt;


How can you mix up the order of values in a PHP array?

To shuffle an array in PHP is easy to do, all you need to use is the shuffle() function like shown below: &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); shuffle($array); // array results will be randomly shuffled ?&gt;


How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?&gt;


How do you reverse the results in a PHP array?

To reverse the results in a PHP array is really simple, all you need to do is use the array_reverse() function like shown below: &lt;?php $my_array = array(1, 2, 3); $reverse_me = array_reverse($my_array); // will be stored as 3, 2, 1 now ?&gt;


How can you create an array of numbers easily in php?

$foo = array(1.41421356, 1.61803399, 2.71828183, 3.14159265);


How do you separate word in array using php?

To separate a sentence into an array of words, you can use PHP's explode() function. If $text is your sentence, then use the following: $result = explode(" ", $text);


What does array map do in php?

The array_map function in PHP loops over each elements of the passed array(s), and runs the given function. It then returns a new array that contains the values returned by each call to the given function.


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 can you check if a value is already in an array in PHP?

To check if a value is already in an array you will need to use the in_array function like shown below! &lt;?php $values = array("pizza","hello","cheese","fred"); $newvalue = "hello"; if (in_array($newvalue, $values)) { echo "$newvalue is already in the array!"; } ?&gt;


Can Array-based lists can never be empty?

It's either an array or it's a list, it cannot be both. However, an empty array is entirely possible: std::vector&lt;int&gt; my_vector; // an empty array my_vector.push_back(42); // an array of 1 element my_vector.push_back(1); // an array of 2 elements my_vector.clear(); // an empty array An empty list is also possible: std::list&lt;int&gt; my_list; // an empty list my_list.push_back(42); // a list of 1 element my_list.push_back(1); // a list of 2 elements my_list.clear(); // an empty list The same thing can be done in C: int* my_array = nullptr; // an empty array my_array = malloc (2*sizeof(int)); // an array of 2 elements my_array[0] = 42; my_array[1] = 1; free my_array; // an empty array my_array = 0;


PHP program to find the minimum number among a list?


How do you count the number of elements in an array using PHP?

Using the function "count". &lt;?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // &lt;-- outputs the number 4 ?&gt;