“Tetapkan $ variabel array pasangan nilai kunci ke beberapa variabel php” Kode Jawaban

Tetapkan $ variabel array pasangan nilai kunci ke beberapa variabel php

$healthStructureData = [
            'product' => $product,
            'website_data' => $website_data,
            'total_keywords' => $total_keywords,
            'certificate_status' => $certificate_status,
            'total_user_websites' => $total_user_websites,
        ];

foreach ($healthStructureData as $key => $value) {
  $$key = $value;
}
Lokesh003Coding

array php


<?php
$array = array(
    "foo" => "bar",
    42    => 24,
    "multi" => array(
         "dimensional" => array(
             "array" => "foo"
         )
    )
);

var_dump($array["foo"]);
var_dump($array[42]);
var_dump($array["multi"]["dimensional"]["array"]);
?>

Condemned Chicken

Tetapkan $ variabel array pasangan nilai kunci ke beberapa variabel php

class Arr
{
    public static function setValue(&$data, $path, $value)
    {
        $temp = &$data;
        foreach ($path as $key) $temp = &$temp[$key];        
        $temp = $value;
        return $value;
    }

    public static function getValue(&$data, $path, $value)
    {
        $temp = &$data;
        foreach ($path as $key) $temp = &$temp[$key];
        return $temp;
    }

    public static function incValue(&$data, $path, $value)
    {
        $temp = (int)self::getValue($data, $path, $value)+$value;
        self::setValue($data, $path, $temp);
    }
}

$d=array();
Arr::incValue($d,array("the","next","value"),10);
echo '<pre>'.json_encode($d, JSON_PRETTY_PRINT);

/*
{
    "the": {
        "next": {
            "value": 10
        }
    }
}
*/
RapTToR

Jawaban yang mirip dengan “Tetapkan $ variabel array pasangan nilai kunci ke beberapa variabel php”

Pertanyaan yang mirip dengan “Tetapkan $ variabel array pasangan nilai kunci ke beberapa variabel php”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya