1

i have script json to aray like this

array (
  'status_code' => 200,
  'status_txt' => 'OK',
  'data' => 
  array (
    'url' => 'http://bit*ly/2jc5mvr',
    'hash' => '2jc5mvr',
    'global_hash' => 'CuJU',
    'long_url' => 'http://github.com/',
    'new_hash' => 1,
  ),
)

how to get short url result from that's array ? i have try this code

$json['url']

But, Not Work.

2
  • 1
    try this echo $json['data']['url']; Commented Nov 9, 2017 at 12:30
  • what's a $json? Where it is initialized? Commented Nov 9, 2017 at 12:31

1 Answer 1

1

Just try:

$json['data']['url']

You're trying to get 'url' from the top-level array, but you need to get it from the sub-level array ('data').

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

2 Comments

It should work. This one is working fine for me and is the right solution.
@FaraazFarzainPermadi Make sure your array is called $json and your array looks how you'd expect it to with var_dump. Also, could you send me the error message that you're getting. "it still does not work" isn't terribly specific. Further than that, I don't think I can help you. I can't debug all your code for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.