-1

My array is :

$firstData=array (
    '000' => array (
        '000' => array (
            0 => '{"code":"11101000000","postal":"3310000","prefecture_kana":""}',
        ),
    ),
)

I want to get postal's value in this array. Could you help me to get postal value 3310000?

0

2 Answers 2

1

I think this is a very basic PHP technique. You can get a value by key ex: $value = $arr['key'].

Let's try

$jsonString = $firstData['000']['000'][0];
$array_from_json = json_decode($jsonString , true);
echo( $array_from_json['postal']);

Explanation

Firstly, you should get a JSON string first

$jsonString = $firstData['000']['000'][0];

$jsonString: '{"code":"11101000000","postal":"3310000","prefecture_kana":""}'

Then, we will parse this JSON string to array by using json_decode:

$array_from_json = json_decode($jsonString , true);

$array_from_json: ["code"=>"11101000000","postal"=>"3310000","prefecture_kana"=>""]

Finally, get value in this array by a key "postal"

$postal = $array_from_json['postal'];

$postal: 3310000

Sign up to request clarification or add additional context in comments.

7 Comments

I try this echo $firstData['postal']; and it works very well
You can copy my edited code and run on this website for checking writephponline.com
$firstData=array ( '000' => array ( '000' => array ( 0 => '{"code":"11000000000","postal":"3456677","prefecture_kana":"","add_1_kana":"","add_2_kana":"","add_3_kana":"","prefecture":"埼玉県","add_1":"","add_2":"","add_3":""}', ), ), ); echo( $firstData['postal']); i try this code on this site. but result is not out :'(
This given input is not similar to the original input. For this input, you should try echo( json_decode($firstData['000']['000'][0], true)['postal']);
I have edited my answer to make it suitable for you question. Please check it. If it can help you please do not forget to mark my answer as an answer to this question
|
0

I think $firstData['postal] @@

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.