融会了,也就熟悉了。

这事得多练,多改。

<?php
    $empty1 = [];
    $empty2 = array();
    $names = ['Harry', 'Ron', 'Hermione'];
    $names['badguy'] = 'Voldemort';
    $names[8] = 'Snape';
    $names[] = 'McGonagall';
    $status = [
        'name' => 'James Potter',
        'status' => 'dead',
    ];

    $names[] = 'Neville';
    $status['age'] = 32;
    unset($status['status']);
    print_r($names);
    print_r('<br/>');
    var_dump(empty($names));
    print_r('<br/>');
    var_dump(isset($names[8]));
    print_r('<br/>');
    var_dump(isset($names[18]));
    print_r('<br/>');
    var_dump(in_array('Neville', $names));
    print_r('<br/>');
    var_dump(in_array('Nevilleb', $names));
    print_r('<br/>');
    var_dump(array_search('Neville', $names));
    print_r('<br/>');
    $names1 = $names2 =$names3 = $names;
    sort($names1);
    var_dump($names1);
    print_r('<br/>');
    asort($names2);
    var_dump($names2);
    print_r('<br/>');
    ksort($names3);
    var_dump($names3);
    print_r('<br/>');
    $keys = array_keys($names);
    $values = array_values($names);
    var_dump($keys);
    print_r('<br/>');
    var_dump($values);
    print_r('<br/>');
    $size = count($names);
    var_dump($size);
    print_r('<br/>');
    $all = array_merge($names, $names1);
    var_dump($all);
    print_r('<br/>');

?>

php中array的常用操作示码-LMLPHP

05-28 02:45