• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Array to String

Beo

Three Magic
Joined
Aug 25, 2009
Messages
9,057
Solutions
1
Reaction score
846
Hi,

Having an issue with php array, thought I'd ask here.

I need to print three arrays to a string, without the Array brackets in the output.

I have these calls
PHP:
$dns = array();
$dd = array();
$cn = array();
while ($row = mysqli_fetch_array($query)) {
  $cn[] = $row['cn'];
  $dns[] = $row['du'];
  $dd[] = $row['ed'];
}

$string = array_map(function($item) {
    return array_combine(['CN', 'DU', 'DD'], $item);
}, array_map(null, $cn, $dns, $dd));

Which is later called to a string. I am using an API which requires this field to be a STRING only. Which I have the below.
PHP:
$ticket = print_r($string, true);

This will provide me with an output of
Code:
Array
(
    [0] => Array
        (
            [CN] => Otland
            [DU] => Otland.net
            [DD] => 2011/11/11
        )

    [1] => Array
        (
            [CN] => Tibia
            [DU] => Tibia.com
            [DD] => 2020/12/09
        )

    [2] => Array
        (
            [CN] => Twitch
            [DU] => Twitch.tv
            [DD] => 2025/11/01
        )

)

I need this to output to (KEEP IN MIND, I have to use Print_r() due to API)
Code:
CN = Otland
DU = otland.net
DD = 11/11/2011

CN = Tibia
DU = Tibia.com
DD = 09/12/2020

CN = Twitch
DU = Twitch.tv
DD = 01/11/2025
 
Last edited:
I'm willing to pay for assistance from someone very knowledgeable in PHP
9. Monetary Offerings:
- Any offerings of money are not allowed in this section. If you want help, ask it but you don't have to offer anything in return other than thanks.
Edit the part where you offer money or I will have to move it to Jobs, You have been here since 2009 should know every rule by now.
 
You could try this. It will dump the $string array, and get the values of the next array and print their key with value.

PHP:
foreach ($string as $values) {
    foreach ($values as $key => $value) {
        // CN = Otland
        echo $key . " = " . $value;
    }
}
 
9. Monetary Offerings:

Edit the part where you offer money or I will have to move it to Jobs, You have been here since 2009 should know every rule by now.
Done - the last time I posted a support request was probably 2009.
 
What kind of silly API is this? Usually you just convert the array to json (which is a string format of passing along data through APIs).
In which case you can use
PHP:
json_encode($array)
, and
PHP:
$array = json_decode($input)
to convert it back to an array.
 
Back
Top