我有以下阵列:如何从数组中返回值?
Array
(
[0] => 32
[1] => Array
(
[uuid] => 92bbf05c-b49e-4950-9d4a-69c226325131
[conversation_uuid] => CON-ee2287cb-ddb7-47e3-9595-0b4d36ac57e3
[status] => failed
[direction] => outbound
)
)
,并希望得到的ID和状态,我有以下代码:
<?php
require __DIR__ . '/../env.php';
//TransferLog Tropo
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
header('Content-Type: application/json');
$body = file_get_contents('callnexmo.log');
//$body = json_decode($json, true);
//$id=$_GET['id'];
//$body=array($id, $json);
//$req_dump = print_r($body, true);
//$fp = file_put_contents('callnexmo.log', $req_dump);
$conn = new mysqli($servername, $username, $password, $database);
//foreach ($body as $value)
//{
$status=$body[1]['status'];
$to=$body[1]['to'];
$from=$body[1]['from'];
$id=$body[0];
echo " body = $body";
var_dump($body);
echo " status = $status";
var_dump($status);
echo " id = $id";
var_dump($id);
//rest of the code
但产量得到我
Warning: Illegal string offset 'status' in /opt/lampp/htdocs/buttoncall/skeleton-application/ficheiros/records/teste.php on line 23
Warning: Illegal string offset 'to' in /opt/lampp/htdocs/buttoncall/skeleton-application/ficheiros/records/teste.php on line 24
Warning: Illegal string offset 'from' in /opt/lampp/htdocs/buttoncall/skeleton-application/ficheiros/records/teste.php on line 25
body = Array
(
[0] => 32
[1] => Array
(
[uuid] => 92bbf05c-b49e-4950-9d4a-69c226325131
[conversation_uuid] => CON-ee2287cb-ddb7-47e3-9595-0b4d36ac57e3
[status] => failed
[direction] => outbound
)
)
string(264) "Array
(
[0] => 32
[1] => Array
(
[uuid] => 92bbf05c-b49e-4950-9d4a-69c226325131
[conversation_uuid] => CON-ee2287cb-ddb7-47e3-9595-0b4d36ac57e3
[status] => failed
[direction] => outbound
)
)
"
status = rstring(1) "r"
id = Astring(1) "A"
我一直在做逻辑类似于这个,它有工作,但现在我似乎把我的手指在错误.. 有人可以帮助我吗?
您误解了传入的数据。你有一串文字“看起来”像一个完全有效的阵列转储。您需要以不同方式存储数据,以便在需要时随时访问它们。如果这个文件超出了你的控制范围,你将不得不用正则表达式或其他东西来破解它。 – mickmackusa
你可能会这样砍:https://regex101.com/r/3CXktP/1 – mickmackusa
你想我发表一个答案吗? – mickmackusa