Y
Y
Yaroslav Studenikin2020-09-03 12:18:18
PHP
Yaroslav Studenikin, 2020-09-03 12:18:18

How to combine two values ​​from a two-dimensional array and get a one-dimensional one?

Hello!
I have an array like this:

Array
(
    [3] => Array
        (
            [ip] => 213.246.6.35
            [port] => 8080
            [hostname] => 188.240.120.136
            [http] => 1
            [https] => 0
            [socks4] => 0
            [socks5] => 0
        )
)

    [15] => Array
        (
            [ip] => 196.54.47.68
            [port] => 80
            [hostname] => 196.54.47.68
            [http] => 1
            [https] => 0
            [socks4] => 0
            [socks5] => 0
        )
)

Is it possible to get only the ip and port values ​​from this array, combine them into one value, and write them into a one-dimensional array? Example:
Array
(
    [0] => 213.246.6.35:3457
    [1] => 196.54.47.68:34557
    [2] => 194.44.15.222:3257
    [3] => 183.89.119.65:984567
)

Please advise possible options.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-09-03
@yar_stun

$new_arr = array();
foreach($arr as $item) {
$new_arr[] = $item['ip'] . ':' . $item['port'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question