Z
Z
zeuss562017-03-01 07:50:26
PHP
zeuss56, 2017-03-01 07:50:26

What are the constructs/operators that work with arrays in PHP?

I wonder if such constructions are possible:

<?php
$arr  = ['a', 'b', 'c', 'd'];
$arr2 = [1 => 'f', 2 => 'c'];

print_r($arr[1,2]);     //1 => 'b', 2 => 'c'
print_r($arr[1..3]);    //1 => 'b', 2 => 'c', 3 => 'd' аналогично array_slice()
print_r($arr - $arr2);  //0 => 'a', 3 => 'd' аналогично array_diff_key()

Probably a stupid question, but I can’t remember the designs, but I can’t find it in the search.
I know about the addition operation, which is equivalent to array_merge().

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2017-03-01
@zeuss56

There are no structures, there are functions.

$arr = ['a', 'b', 'c', 'd'];
print_r(array_slice($arr, 1, 3));
Array
(
    [0] => b
    [1] => c
    [2] => d
)

V
Viktor Yanyshev, 2017-03-01
@villiwalla

Maybe this list will help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question