search
HomeBackend DevelopmentPHP TutorialIntroduction to photoshop learning PHP learning array courseware page 1/2

Subscript: The identification name in the array, which is the codename of the string or integer in the array. The array with several index values ​​is called a multi-dimensional array.
Index value: An index is a structure that sorts the values ​​of one or more columns in a database table.
Array classification
Arrays in PHP are divided into two types:
Indexed array: Indexed (indexed) index value is an integer, starting with 0. Indexed arrays are used when identifying things by position.
Associative array: Associative association uses a string as the index value, and the index value is the column name, and is used to access the column data.
Arrays are usually assigned values ​​
Generally, there are two ways to assign values ​​to arrays:
$a[1]="dsadsadsa";
$b[2]="dsadsadsad";
Use the array function:
$a=array ("dsads","dsadsa",321312);
One-dimensional array: When the array has only one index value (subscript), it is called a one-dimensional array.
Format of direct array assignment:
$Array variable name [index value] = data content;
Note: The index value can be a string or an integer, but 1 and "1" are different. One of them belongs to an integer and the other to a string. .
Arrays with the same name without index values ​​are arranged in order.
Example:
$a=array(1,2,3,4,5,6);
$b=array("one", "two", "three");
$c= array(0=>"aaa",1=>"bbb",2=>"ccc");
  $d=array("aaa",6=>"bbb","ccc");
    $e=array("name"=>"zhang", "age"=>20);
?>
    Two-dimensional array
The format of multi-dimensional array:
$a[0][]="dsadas ";
$a[0][]="dsadsa"; This group is 1 and 2 under the 0 index value under $a
If you use the array function to declare the format as follows:
$a=array("dsadsa"," dsadas",21,array("dsadsa","dsadas"));
Array traversal
foreach loop structure:
foreach only uses two formats: array loop
foreach(array_exprssion(array expression) as $value);
foreach(array_exprssion(array expression) as $key=>$value);
The first format traverses the given array_exprssion array. Each time through the loop the current value is assigned to my $calue and the pointer inside the array moves forward one step.
The second format does the same thing, except that the key value of the current cell will also be assigned to the variable $key in each loop.
When foreach starts executing, the pointer inside the array will automatically point to the first unit. Also note that foreach operates on a copy of the specified array, not the array itself
$arr=array(10,20,30,40,50,60);
foreach($arr as $k=>$v ){
echo "$k=>$v
";
}
Output result: 0=>10 1=>20 2=>30 3=>40 4=>50 5= >60//Subscript=>Integer
Combining list(), each() and while loop
each():
$arr=array(1,2,3,4,5);
$a= each($arr);
print_r($a);
Output result: Array ( [1] => 1 [value] => 1 [0] => 0 [key] => 0 )
Get Get the first value of the array value subscript key
list():
$arr3=array("a","b","c");
list($key,$value)=each($arr3) ;
echo $key."
".$value;
Output result: 0 a List() can be said to assign values ​​to a set of variables in one step. It can only be used for numerically indexed arrays and assumes that the numerical index starts from 0 start.
while loop
$arr=array(1,2,3,4,5,6,7,8,9,);
while(list($key,$value)=each($arr)){
$ key++;
echo $key."=>".$value;
echo "
";
}
echo "
";
Output result: 1=>1 2=>2 3=>3 4=>4 5=>5 6=>6 7=>7 8=>8 9=>9
reset() array pointer redirection
After executing each() , the array pointer will stay at the next element in the array or at the last element when the end of the array is reached.
is_array detects whether the variable is an array and returns true or false.
$arr=array(1,2,3,4,5,6,"saas");
while(list($k,$v) = each($ arr))
{
if(is_array($arr))
{
$x += $v;
echo $x;
}
else
{
$ x += $k;
}
}
This example It cannot fully reflect the function of is_array, but it can be used as a reference.
The pointer of the array
next(): responsible for moving the pointer backward
prve(): responsible for moving the pointer forward
end(): will point the pointer to the last element of the array
reset(): unconditionally move the current pointer to The first index position
Syntax format: mixed next(array name)
$arr=(array(1,2,3,4,5));
echo end($arr);
Output result: 5
key( ), current() and count()
key() function is to read the index value of the data pointed to by the current pointer.
The current() function reads the content data of the data pointed to by the current pointer. The
count() function is used to count the number of all elements in the array, which means that the function will return the length value of the target array.
Format: int count (array name);
key(): Get the key name from the associative array
$array = array('fruit1' => 'apple','fruit2' => 'orange','fruit3 ' => 'grape','fruit4' => 'apple','fruit5' => 'apple');
while ($fruit_name = current($array)) {
if ($fruit_name == ' apple') {
echo key($array).'
';
next($array);
}
Output result: fruit1,fruit4,fruit5
current(): Returns the value in the array Current unit
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next( $transport); // $mode = 'bike';
$mode = current($transport); // $mode = 'bike';
$mode = prev($transport); // $mode = 'foot' ;
$mode = end($transport); // $mode = 'plane';
$mode = current($transport); // $mode = 'plane';
Pay attention to the example to return the current unit in the array
count(): Calculate the number of units in the array
$arr=array(1,2,3,4,5,6);
echo count($arr);
Output result: 6
array_change_key_case()
array_change_key_case returns An array whose string key names are all lowercase or uppercase contains two morphological functions: [CASE_UPPER] to convert to uppercase, and [CAS_LOWER] to convert to lowercase.
$input_array = array("FirSt" => 1, "SecOnd" => 4);
print_r(array_change_key_case($input_array, CASE_UPPER));
Output result: Array ( [FIRST] => 1 [SECOND ] => 4)
 array_chunk() The
array_chunk() sub-function will decompose the data content of the target array into several small arrays with the specified number of indexes and include them in the original array.
$arr=array(1,2,3,4,5,6);
$a=array_chunk($arr,3);
print_r($a);
Output result: Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [1] => Array ( [0] => 4 [1] => 5 [2] = > 6 ) )
It is equal to dividing the sum of the number of array units by 3
array_count_values ​​
array_count_values ​​is used to calculate the number of occurrences of each value in the target array
Syntax format: array_count_values ​​(target array)
The result returned by this function The value will be expressed in the form of an array using the content data of the original array as an index.
$arr=array(1,2,3,3,2,6);
print_r(array_count_values($arr));
Output result: Array ( [1] => 1 [2] => 2 [ 3] => 2 [6] => 1)

Current page 1/2 12Next page

The above introduces page 1/2 of the introductory learning of photoshop and php learning array courseware, which includes the content of introductory learning of photoshop. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!