第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從print_r打印的數(shù)組的輸出創(chuàng)建一個數(shù)組?

如何從print_r打印的數(shù)組的輸出創(chuàng)建一個數(shù)組?

如何從print_r打印的數(shù)組的輸出創(chuàng)建一個數(shù)組?我有一個數(shù)組:$a = array('foo' => 'fooMe');我這樣做:print_r($a);打印:Array ( [foo] => printme )有沒有功能,所以在做的時候:needed_function('    Array ( [foo] => printme )');我會把陣列拿array('foo' => 'fooMe');回來嗎?
查看完整描述

3 回答

?
幕布斯6054654

TA貢獻1876條經(jīng)驗 獲得超7個贊

如果要將數(shù)組存儲為字符串,請使用serialize [docs]unserialize [docs]。

回答你的問題:不,沒有內(nèi)置函數(shù)可以print_r再次解析數(shù)組的輸出。


查看完整回答
反對 回復 2019-08-02
?
小唯快跑啊

TA貢獻1863條經(jīng)驗 獲得超2個贊

對于使用子陣列的數(shù)組輸出,ninetwozero提供的解決方案將不起作用,您可以嘗試使用適用于復雜數(shù)組的此函數(shù):

<?php

$array_string = "

Array
 (
   [0] => Array
    (
       [0] => STATIONONE
       [1] => 02/22/15 04:00:00 PM
       [2] => SW
       [3] => Array
            (
                [0] => 4.51
            )

        [4] => MPH
        [5] => Array
            (
                [0] => 16.1
            )

        [6] => MPH
    )

     [1] => Array
    (
        [0] => STATIONONE
        [1] => 02/22/15 05:00:00 PM
        [2] => S
        [3] => Array
            (
                [0] => 2.7
            )

        [4] => MPH
        [5] => Array
            (
                [0] => 9.61
            )

        [6] => MPH
    )
)
";print_r(print_r_reverse(trim($array_string)));function print_r_reverse(&$output){
    $expecting = 0; // 0=nothing in particular, 1=array open paren '(', 2=array element or close paren ')'
    $lines = explode("\n", $output);
    $result = null;
    $topArray = null;
    $arrayStack = array();
    $matches = null;
    while (!empty($lines) && $result === null)
    {
        $line = array_shift($lines);
        $trim = trim($line);
        if ($trim == 'Array')
        {
            if ($expecting == 0)
            {
                $topArray = array();
                $expecting = 1;
            }
            else
            {
                trigger_error("Unknown array.");
            }
        }
        else if ($expecting == 1 && $trim == '(')
        {
            $expecting = 2;
        }
        else if ($expecting == 2 && preg_match('/^\[(.+?)\] \=\> (.+)$/', $trim, $matches)) // array element
        {
            list ($fullMatch, $key, $element) = $matches;
            if (trim($element) == 'Array')
            {
                $topArray[$key] = array();
                $newTopArray =& $topArray[$key];
                $arrayStack[] =& $topArray;
                $topArray =& $newTopArray;
                $expecting = 1;
            }
            else
            {
                $topArray[$key] = $element;
            }
        }
        else if ($expecting == 2 && $trim == ')') // end current array
        {
            if (empty($arrayStack))
            {
                $result = $topArray;
            }
            else // pop into parent array
            {
                // safe array pop
                $keys = array_keys($arrayStack);
                $lastKey = array_pop($keys);
                $temp =& $arrayStack[$lastKey];
                unset($arrayStack[$lastKey]);
                $topArray =& $temp;
            }
        }
        // Added this to allow for multi line strings.
    else if (!empty($trim) && $expecting == 2)
    {
        // Expecting close parent or element, but got just a string
        $topArray[$key] .= "\n".$line;
    }
        else if (!empty($trim))
        {
            $result = $line;
        }
    }

    $output = implode("\n", $lines);
    return $result;}/**
* @param string $output : The output of a multiple print_r calls, separated by newlines
* @return mixed[] : parseable elements of $output
*/function print_r_reverse_multiple($output){
    $result = array();
    while (($reverse = print_r_reverse($output)) !== NULL)
    {
        $result[] = $reverse;
    }
    return $result;}?>

有一個小bug,如果你有一個空值(空字符串),它會嵌入到之前的值中。


查看完整回答
反對 回復 2019-08-02
  • 3 回答
  • 0 關注
  • 1110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號