Home  >  Article  >  Backend Development  >  PHP Basics 1: Arrays and Data Structures

PHP Basics 1: Arrays and Data Structures

不言
不言Original
2018-04-26 14:24:501813browse

The content introduced in this article is about the basics of php, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

<!-- PHP数组与数据结构 -->

<?php
// //     $arr = array(&#39;欢迎&#39;,10 => &#39;学习&#39;,
// //         &#39;php&#39;,
// //         19 => &#39;语言&#39;,&#39;相信自己一定能学会&#39;
// //     );
    
// //     $arr = array(&#39;刘亦菲&#39;,
// //         &#39;anglebaby&#39;,&#39;鹿晗&#39;,&#39;范彬彬&#39;
// //     );
    
//     $arr[0] = &#39;北京&#39;;
//     $arr[1] = &#39;上海&#39;;
//     $arr[2] = &#39;广州&#39;;

//     $arr = array(&#39;0&#39; => &#39;小明&#39;,
//         &#39;1&#39; => &#39;小龙&#39;,
//         &#39;2&#39; => &#39;小花&#39;,
//         &#39;3&#39; => &#39;小兰&#39;
//     );
    
//     $arr = [
//         [&#39;南宁&#39;,&#39;崇左&#39;,&#39;凭祥&#39;,&#39;桂林&#39;,&#39;百色&#39;],
//         [&#39;龙州&#39;,&#39;武鸣&#39;,&#39;宁明&#39;,&#39;大兴&#39;,&#39;苹果&#39;]
//     ];
    
//     $arr = array(
//         array(&#39;南宁&#39;,&#39;崇左&#39;,&#39;凭祥&#39;,&#39;桂林&#39;,&#39;百色&#39;),
//         array(&#39;龙州&#39;,&#39;武鸣&#39;,&#39;宁明&#39;,&#39;大兴&#39;,&#39;苹果&#39;)
//     );
    
//     echo &#39;<pre class="brush:php;toolbar:false">&#39;;
//     echo count($arr);die;
//     var_dump($arr[2]);
//     echo &#39;
'; ?> '; } unset($num[1]); var_dump($num); $name = array( 'name1' => '芙蓉', 'name2' => '凤姐' ); foreach ($name as $key => $value){ echo $key.'——————'.$value.'
'; } $city = array( 0 => array( '南宁' => 'nanning', '百色' => 'baise', '凭祥' => 'pingxing' ), 1 => array( '广州' => 'guangzou', '深圳' => 'shengzheng', '东莞' => 'dongguan' ) ); foreach ($city as $value){ foreach ($value as $k => $v){ echo $k.'—'.$v.'
'; } } list($one,$two,$three) = array('张三','李四','王五'); echo '$one----'.$one.'
'; echo '$two----'.$two.'
'; echo '$three--'.$three.'
'; $kongjie = [ 'gao' => '黑丝', 'lian' => '很白', 'tui' => '很细', 'wuguan' => '精致', 'shengyin' => '甜美', ]; $date = each($kongjie); echo '
&#39;;
    var_dump($date);
    echo &#39;<pre class="brush:php;toolbar:false">&#39;;
    list($one,$two) = each($kongjie);
    echo $one.&#39;-&#39;.$two.&#39;<br />&#39;;
    
    $minggren = array("邓超","黄晓明","泞泽涛","钟汉良");
    $dc = array_shift($minggren);
    array_unshift($array, $value1);
    array_push($array, $value1);
    array_pop($array);
    current($array);
    key($array);
    next($array);
    prev($array);
    reset($array);
    end($array);
    print_r($minggren);
    
    //php数组常用函数
    array_combine($keys, $values);
    range($start, $end);
    compact($varname1);
    array_fill($start_index, $num, $value);
    array_chunk($array, $size);
    array_merge($array1);
    array_slice($array, $offset);
    array_diff($array1, $array2);
    array_search($needle, $haystack);
    array_splice($input, $offset);
    array_sum($array);
    in_array($needle, $haystack);
    array_key_exists($key, $array);
    shuffle($array);
    count($array_or_countable);
    array_flip($array);
    array_keys($array);
    array_values($array);
    array_reverse($array);
    array_count_values($array);
    array_rand($array);
    array_unique($array);
    sort($array);
    rsort($array);
    asort($array);
    arsort($array);
    asort($array);
    arsort($array);
    ksort($array);
    krsort($array);
    natsort($array);
    natcasesort($array);
    array_filter($array);
    extract($array);
    
?>


The above is the detailed content of PHP Basics 1: Arrays and Data Structures. For more information, please follow other related articles on the PHP Chinese website!

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