S
S
siroper2020-08-26 20:39:37
PHP
siroper, 2020-08-26 20:39:37

How to get id from array key?

Hello. There is an array $result
print_r($result) returns:

Array
(
    [id:33002, date] => 26.08.2020 17:21:30
    [to] => 123
    [out] => 321
    [status] => 1
)


This is the first time I've come across this. How to get the id value separately (33002)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gennady S, 2020-08-26
@siroper

The question is probably how to get the key? Because in your case, you can get an identifier from a similar string in any convenient way:

$id = null;
reset($array); // надежнее обнаружить нужный ключ перебором и последующей проверкой
$key = key($array);
$match = null;
if ( preg_match('/^id:(\d+)/', $key, $match) ) $id = (int) $match[1];

R
runapa, 2020-08-26
@runapa

$result['id']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question