如何从数组的数组中获取值



我需要从这段代码中获取标题摘要封面值。请帮我获取原始数据的值,我需要循环它们。有人能帮我吗

Array
    (
        [rawData] => Array
            (
                [csrf_hash_name] => 57b9481862e81cf2ebe9ed4e962355db
                [title] => gfgf
                [summary] => hfdhfhfdhdf
                [cover] => clockface - 2.png
                [id] => Array
                    (
                        [0] => 
                        [1] => 
                    )

    )

只需按其键调用即可:

$arr = Array
(
    'rawData' => Array
        (
            'csrf_hash_name' => 57b9481862e81cf2ebe9ed4e962355db,
            'title' => gfgf,
            'summary' => hfdhfhfdhdf,
            'cover' => clockface - 2.png,
            'id' => Array
                (
                    0 => '',
                    1 => ''
                )

);

然后使用

$title = $arr['rawData']['title'];
$summary = $arr['rawData']['summary'];

在下面尝试此代码

<?php 
$array = array(
    "rawData" => array(
        "csrf_hash_name" => "57b9481862e81cf2ebe9ed4e962355db",
        "title" => "gfgf",
        "summary" => "hfdhfhfdhdf",
        "cover" => "clockface - 2.png",
        "id" => array(
            0 => "",
            1 => ""
        )
    )
);
foreach($array["rawData"] as $key => $arr) {
    $fetchValue = array('title', 'summary', 'cover');
    if(in_array($key, $fetchValue)) {
        $$key = $arr;
    }
}
echo $title;
echo $summary;
echo $cover;
?>

干杯!

<?php 
$array = array(
    "rawData" => array(
        "csrf_hash_name" => "57b9481862e81cf2ebe9ed4e962355db",
        "title" => "gfgf",
        "summary" => "hfdhfhfdhdf",
        "cover" => "clockface - 2.png",
        "id" => array(
            0 => "",
            1 => ""
        )
    )
);
$arr2 = array();
foreach($array["rawData"] as $key => $arr) {
    $fetchValue = array('title', 'summary', 'cover');
    if (in_array($key, $fetchValue)) {
        $arr2[$key] = $arr;
    }
}
extract($arr2);
echo $title;
echo '<br/>';
echo $summary;
echo '<br/>';
echo $cover;
?>

相关内容

  • 没有找到相关文章

最新更新