Detailed explanation of how to add and delete search operations for php array values

Source: Internet
Author: User
The php array is divided into array values and array keys. The following small series will summarize the common operations for array values in php: for more information about php tutorials, such as adding values to an array, determining values in an array, and deleting specific array values, see. Php enthusiasts share their development experiences. php deletes a specific array value var_dump ($ context [

The php array is divided into array values and array keys. The following small series will summarize the common operations for array values in php: for more information about php tutorials, such as adding values to an array, determining values in an array, and deleting specific array values, see. Php enthusiasts share their development experiences. php deletes the specified array value var_dump ($ context ['

The php array is divided into array values and array keys. The following small series will summarize the common operations for array values in php: for more information about php tutorials, such as adding values to an array, determining values in an array, and deleting specific array values, see. Php enthusiasts share their development experiences

Php deletes a specific array value

Var_dump ($ context ['linktree']);

The

Array (3 ){
[0] =>
Array (2 ){
["Url"] =>
String (52) "http: // 127.0.0.1/testforum.cityofsteam.com/index.php"
["Name"] =>
String (28) "City of Steam Official Forum"
}
[1] =>
Array (2 ){
["Url"] =>
String (55) "http: // 127.0.0.1/testforum.cityofsteam.com/index.php?c1 ″
["Name"] =>
String (28) "City of Steam Official Forum"
}
[2] =>
Array (2 ){
["Url"] =>
String (62) "http: // 127.0.0.1/testforum.cityofsteam.com/index.php? Board = 4.0 ″
["Name"] =>
String (12) "Announcement"
}
}

I want to remove the middle one.

Use: unset ($ context ['linktree'] ['1']);

Array (2 ){
[0] =>
Array (2 ){
["Url"] =>
String (52) "http: // 127.0.0.1/testforum.cityofsteam.com/index.php"
["Name"] =>
String (28) "City of Steam Official Forum"
}
[2] =>
Array (2 ){
["Url"] =>
String (62) "http: // 127.0.0.1/testforum.cityofsteam.com/index.php? Board = 4.0 ″
["Name"] =>
String (12) "Announcement"
}
}

One [1] is missing.

Let the Middle 1 be automatically numbered:

Array ([0] => apple [1] => banana [3] => dog)

Function array_remove (& $ arr, $ offset)

{

Array_splice ($ arr, $ offset, 1 );

}

$ Arr = array ('apple', 'Banana ', 'cat', 'Dog ');

Array_remove ($ arr, 2 );

Print_r ($ arr );

?>

After testing, we can know that the element 2 is actually deleted and the index is re-created.

Original article address: added the delete search operation method for php array values. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.