Skip to main content
added 30 characters in body
Source Link
The fourth bird
  • 164.7k
  • 16
  • 61
  • 75

You might use a forfor loop with anand check if the index from $words exists in $skus:

$skus = [ 

    "Hello",
    "world",
    "sky",
    "is",
    "blue",
];

$words = array(0,2,4);
$result = [];
for ($i = 0; $i < count($words); $i++) {
    if (isset($skus[$words[$i]])) {
        $result[$i] = $skus[$words[$i]];
    }
}

print_r($result);

Result

Array
(
    [0] => Hello
    [1] => sky
    [2] => blue
)

Php demoPhp demo

You might use a for loop with an index:

$skus = [
    "Hello",
    "world",
    "sky",
    "is",
    "blue",
];

$words = array(0,2,4);
$result = [];
for ($i = 0; $i < count($words); $i++) {
    $result[$i] = $skus[$words[$i]];
}

print_r($result);

Result

Array
(
    [0] => Hello
    [1] => sky
    [2] => blue
)

Php demo

You might use a for loop and check if the index from $words exists in $skus:

$skus = [ 

    "Hello",
    "world",
    "sky",
    "is",
    "blue",
];

$words = array(0,2,4);
$result = [];
for ($i = 0; $i < count($words); $i++) {
    if (isset($skus[$words[$i]])) {
        $result[$i] = $skus[$words[$i]];
    }
}

print_r($result);

Result

Array
(
    [0] => Hello
    [1] => sky
    [2] => blue
)

Php demo

Source Link
The fourth bird
  • 164.7k
  • 16
  • 61
  • 75

You might use a for loop with an index:

$skus = [
    "Hello",
    "world",
    "sky",
    "is",
    "blue",
];

$words = array(0,2,4);
$result = [];
for ($i = 0; $i < count($words); $i++) {
    $result[$i] = $skus[$words[$i]];
}

print_r($result);

Result

Array
(
    [0] => Hello
    [1] => sky
    [2] => blue
)

Php demo