PHP Development notes series (9)-array (2)

Source: Internet
Author: User
PHP Development notes series (9)-array (2 )???? I wrote "PHP development note series (9)-array (1)" before going to bed last night, and continued to write "PHP development note series (9)-array (2)" tonight. after Php numeric key array, join key array, multi-dimensional array creation, extraction, array type judgment, and output array, let's take a look at the Php PHP Development notes series (9)-array (2)

???? I wrote "PHP development note series (9)-array (1)" before going to bed last night, and continued to write "PHP development note series (9)-array (2)" tonight. after Php numeric key array, join key array, multi-dimensional array creation, extraction, array type judgment, and output array, we will study the subsequent content of the Php array today.


??? 1. output array

??? In daily Php program development, arrays are the most frequently used data types. for example, the specified data is returned from the database through the join key array type based on the query conditions, check whether the results of the association key array returned by the program are correct and missing. you can use debug to view the returned results in the variable view, if you want to check the results in a faster way, you can use the print_r () function.


??? The print_r () function outputs the array content to the screen to test and check the content. The print_r () function accepts a variable and sends the content to the standard output. if the result is successful, TRUE is returned. otherwise, FALSE is returned.


??? If the second parameter is passed to print_r (), TRUE or? FALSE. if it is TRUE, print_r () returns the output to the caller rather than the standard output.

?

?

file: print_r.phpurl: http://localhost:88/array/print_r.php
 ";    echo "========================";    echo "
"; $return = print_r($data, TRUE); echo $return;?>

?

??? 2. add elements to the array header

??? Add an element to the value key array header and use array_unshift (). after adding the element, the value key in the array is automatically updated. the code is as follows:

?

file: unshift.phpurl: http://localhost:88/array/unshift.php
  $value) {        echo $key.":".$value."
"; } ?>

?

??? When adding elements to the join key array header, the elements in the join key array are not sequential, so the order is not very important during access, so the array_unshift () function is rarely used.


??? 3. add elements to the end of the array

??? Add an element at the end of the value key array and use array_push (). after adding the element, the value key in the array is automatically updated. the code is as follows:

?

file: push.phpurl: http://localhost:88/array/push.php
  $value) {        echo $key.":".$value."
"; } ?>

?

??? 4. delete the array header element

??? Use array_shift () to delete an element from the value key array header. after adding the element, the value key in the array is automatically updated. the code is as follows:

???

file: shift.phpurl: http://localhost:88/array/shift.php
  $value) {        echo $key.":".$value."
"; } ?>
?

?

??? 5. delete the end element of the array.

??? Delete the element at the end of the value key array and use array_pop (). after adding the element, the value key in the array is automatically updated. the code is as follows:

?

file: pop.phpurl: http://localhost:88/array/pop.php
  $value) {        echo $key.":".$value."
"; } ?>

?

??? 6. search for arrays

??? The in_array () function searches for a specific value in the array. if this value is found, TRUE is returned. otherwise, FALSE is returned.

?

file: in_array.phpurl: http://localhost:88/array/in_array.php
 

?

??? The in_array () function also accepts the third parameter, which forces the search to consider the type.


??? 7. search for the join key array key

??? The arrar_key_exists () function searches for the specified key value in an array. If yes, TRUE is returned. otherwise, FALSE is returned.

?

file: array_key_exists.phpurl: http://localhost:88/array/array_key_exists.php?php    $map['1st'] = '1st value';     $map['2nd'] = '2nd value';     $map['3rd'] = '3rd value';    $flag = array_key_exists('1st', $map);        echo $flag ? "TRUE" : "FALSE";    ?>

?

??? 8. search for associated array values

??? The array_search () function searches for a specified value in an array. If yes, TRUE is returned. otherwise, FALSE is returned.

?

file: array_search.phpurl: http://localhost:88/array/array_search.php
 
?

??? 9. get all array keys

??? The array_keys () function returns an array containing all the key values.

???

file: array_keys.phpurl: http://localhost:88/array/array_keys.php
 

?

??? 10. get all array values

??? The array_values () function returns an array containing all values.

?

file: array_values.phpurl: http://localhost:88/array/array_values.php
 
?

???? Write it here again tonight and continue tomorrow night.


??? Address: http://ryan-d.iteye.com/blog/1566532

?

?

?

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.