dir.by  
  Поиск  
Компьютер, программы
PHP (язык программирования для быстрого написания Web сайта)
 Array in PHP (Create an array, add elements, the length of the array, go through all the elements in the array) 
посмотрели 1710 раз
обновлено: 5 December 2024
To work with an array in PHP, use the array class.
1. Create an empty array
  PHP  
$my_arr1 = array();
2. Create a populated array
  PHP  
$my_arr1 = array("Hello", "Home", "Good");
3. Adding New Elements to the End of an Array
  PHP  
$my_arr1[] = "Hello";
$my_arr1[] = "Home";
$my_arr1[] = "Good";
4. Array length
The count method is the number of elements in the array.
  PHP  
$myCount = count($my_arr1);
// $myCount = 3
5. Go through all the elements in the array
  PHP  
for ($i=0; $i<;count($my_arr1); $i++)
{
     $my_element = $my_arr1[$i];

     // on first iteration
     // $my_element = "Hello"

     // on second iteration
     // $my_element = "Home"

     // on third iteration
     // $my_element = "Good"
}
 
← Previous topic
Pass the unnamed function as a parameter to the | using use (...) the unnamed function sees the variable above | PHP
 
Next topic →
Look for an element in an array in PHP | array_search
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Экскурсии по Москве Экскурсии по Москве: пешеходные, автобусные и речные прогулки на любой вкус
Анонс! Ярмарка вакансий для молодежи, работа (учащихся, которые хотели бы подработать в свободное время, а также выпускники)|||Минск, Витебск, Гомель, Гродно, Могилев, Борисов, Полоцк, Брест, Барановичи, Пинск с 13 по 17 апреля 2026
  Объявления  
  Объявления  
 
PHP Study
Что такое PHP ?
Function
Function in PHP. Example: function CalculateSum($value1, $value2) { ... }
Passing parameters by value and by reference to a function in PHP
Pass a function as a parameter to a function | PHP
Unnamed function
Anonymous function (no name). Function pointer in PHP
Pass the unnamed function as a parameter to the | using use (...) the unnamed function sees the variable above | PHP
Arrays
Array in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
Look for an element in an array in PHP | array_search
Key-value arrays
Array (key-value) in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
Regular expressions
Регулярные выражения
PHP Server
Create an html file and javascript sends a post request to the php server. PHP server makes the answer | Why on php server $_REQUEST or $_POST array is empty
Framworks (frameworks)
Zend Framework (PHP framework)
Yii (PHP framework)
CakePHP (framework)

  Ваши вопросы присылайте по почте: info@dir.by  
Яндекс.Метрика