0

The Situation

I'm currently decoding my array into JSON and display it The structure is like that:

["value1","value2","value3","..."]

I want that data in an API request. So I thought of saving it to a variable and put that in the api request but I always get the error message invalid input format. Since the API request needs the data like this:

API URL: "http://somedomain.com/api?=key:=searchfor=value1>>value2>>value3>>..."

My previous approach was:

"http://somedomain.com/api?=key:=searchfor=$mycustomarray"

I tried it with an array and JSON data but both wont work for the request.

What I want to achieve

I want to get that data displayed in the format I need it for that API request. Is there a way to get the JSON or Array in the desired format: I should be put in the api request like:

[value1>>value2>>value3>>...]

I would appreciate any help

2
  • 1
    Use implode on your array. php.net/manual/en/function.implode.php that is implode(">>",$yourArray); Commented Jun 29, 2017 at 4:01
  • 1
    You can use implode and append all elements with '>>' in the array and send it as a string in the url Commented Jun 29, 2017 at 4:01

1 Answer 1

1

Try this

<?php

$a = array("value1","value2","value3");

$b = implode('>>',$a);

print_r($b);

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

3 Comments

Is there anything about JSON in your answer ? you should have used json_encode or json_decode with proper uses.
no he need to display the json or array in the format value1>>value2 that's why i didn't mention anything about json
He is using PHP in APIs so I guess he would be needing it to Callback APIs

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.