Send array to JSON PHP [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I got these arrays
$address = array("1JzSZFs2DQke2B3S4pBxaNaMzzVZaG4Cqh", "12Cf6nCcRtKERh9cQm3Z29c9MWvQuFSxvT", "1dice6YgEVBf88erBFra9BHf6ZMoyvG88")
$amount= array("100000000","150000000","200000000")
and I want to convert them to json format like below:
{
"1JzSZFs2DQke2B3S4pBxaNaMzzVZaG4Cqh": 100000000,
"12Cf6nCcRtKERh9cQm3Z29c9MWvQuFSxvT": 1500000000,
"1dice6YgEVBf88erBFra9BHf6ZMoyvG88": 200000000
}
I tried too much but couldn't figure out how to do that in PHP, any ideas?

Use array_combine:
echo json_encode(array_combine($address, array_map('intval', $amount)));

Related

Spread argumnts function functionName(...$nums) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 days ago.
Improve this question
I made a spread and it converts the Parameter to the array. it works fine but I don't understand how it happened.
The Code under below ::
function ava (...$nums){
return $nums;
}
Print_r (ava(100, 100, 100, 100));
also have a question of spread can be used with string by PHP ?

how to create dynamic string in php like sample? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
hi i want to create string in laravel with foreach and that string must be like this sample:
'item1,item2,item3'
Pay attention to commas and quotation marks.
anyone can help me?
you can use implode function.
Have a look at https://www.php.net/implode
It does exactly that with arrays.
example:
$string = implode(",", $array);

How do I post this JSON data with PHP? This JSON different [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
This is JSON data
{"clanSearch":{"results":[{"tag":"#G90G8RCU","name":"codex2015.asia","type":"open","locationName":"Indonesia","clanBadgeImg":{"s":"https://api-assets.clashofclans.com/badges/70/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png, https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png 2x","m":"https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png, https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png 2x","l":"https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png","xl":"https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png"},"warFrequency":"always","clanLevel":1,"clanPoints":6867,"warWins":0,"requiredTrophies":0,"members":12}]}}
Here is the link
and my PHP code
$json = json_decode(file_get_contents("https://set7z18fgf.execute-api.us-east-1.amazonaws.com/prod/?route=getClanSearch&name=codex2015.asia"));
$info = "$json->{'tag'}";
echo $info;
In this case, I want to get tag data, but if I run this script I get nothing.
$json = json_decode(trim(file_get_contents("url",true)));
$info = $json['clanSearch']['results'][0]['tag'];
echo $info;
Usetrue flag and the hole data is converted to arrays with sub arrays
If you dont use true you have to get it with:
$json->clanSearch->results[0]->tag;

Pass a URL as a get parameter in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
http://example.com/geturl.php?url=http://example.org/index.php?parafile=1698%3A1562%3A0%3A0&para_action=print_ticket&parafile=dance://here.kodas/print&token=3ec2b0d3e6e0ca152bc024cc3f30f16c
So i want each of this parameters in a different varaible in the geturl.php file. I am using the regular get url
You can use anything like this :
$url = "http://example.com/geturl.php?url=".urlencode($urlPart);
$_server[QUERY_STRING] solved my problem

Display JSON File content using PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can i display (echo) the JSON File content, like here, NOT DECODED?
http://api.androidhive.info/contacts/index.php
Thank You!
If your on php 4.5 or above you can use the JSON_PRETTY_PRINT.
$json_string = json_encode($data, JSON_PRETTY_PRINT);

Categories