在动态多维数组中按键获取数组值

时间:2017-11-15 08:09:35

标签: php arrays multidimensional-array

我有一个多维数组,它是使用另一个函数动态生成的。多维数组由3-d和4-d元素组成。我在下面添加了数组示例。现在,用户想要通过仅传递数组的键来设置此数组的特定值(因为用户不能直接访问此数组)。所以我需要通过使用用户传递的键来访问数组的特定元素的方法。请告诉我。提前谢谢。

用户将传递类似的内容 例如$ newdata [“company”] [“logo”] [“data”] =“newlogourl”;`这个值需要在原始数组中替换。

Array
(
    [company] => Array
        (
            [logo] => Array
                (
                    [data] => https://www.sparksuite.com/images/logo.png
                    [style] => width:100%; max-width:300px
                )

            [name] => Array
                (
                    [data] => Company Name, Inc
                )

            [tagline] => Array
                (
                    [data] => Company Name, Inc
                )

        )

    [invoice] => Array
        (
            [no] => Array
                (
                    [data] => DY-13123
                    [label] => Invoice No: 
                    [style] => font-size:14px
                )

            [date] => Array
                (
                    [data] => 01-12-2018
                    [label] => Date: 
                )

            [total_due] => Array
                (
                    [data] => $56,890.23
                    [label] => Total Due: 
                    [display] => show
                )

        )

    [from] => Array
        (
            [name] => Array
                (
                    [data] => Apple Test Inc 
                )

            [address1] => Array
                (
                    [data] => 123 Seatle
                )

            [address2] => Array
                (
                    [data] => New jersy
                )

            [city] => Array
                (
                    [data] => Indore
                )

            [state] => Array
                (
                    [data] => M.P
                )

        )

    [to] => Array
        (
            [name] => Array
                (
                    [data] => American Option
                )

            [address1] => Array
                (
                    [data] => 205, Apollo Tower, Near Palasia
                )

            [address2] => Array
                (
                    [data] => Opp. 56 Shops, M.G Road
                )

            [city] => Array
                (
                    [data] => Indore
                )

            [state] => Array
                (
                    [data] => M.P
                )

        )

    [payment] => Array
        (
            [method] => Array
                (
                    [data] => DY-13123
                    [label] => Payment methods: 

                )

            [note] => Array
                (
                    [data] => Thank you for Business with us!
                    [label] => 
                )

        )

    [footer] => Array
        (
            [note] => Array
                (
                    [data] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
                    [label] => Terms and Conditions: 

                )

        )

    [itemcount] => Array
        (
            [count] => Array
                (
                    [label] => Sno.
                )

            [display] => show
        )

    [header] => Array
        (
            [style] => font-size:18px
            [display] => show
        )

)

0 个答案:

没有答案