Home > Mobile >  How to store $_Post values separated by &
How to store $_Post values separated by &

Time:10-18

I did

file_put_contents("x.txt", print_r($_POST, true));    

And I got the below output

Array
    (
        [merchant_id] => ece6ba4ecx24d070b4c13b
        [invoice_id] => 1772fb6eafda04ceb11c77cf719a347f
        [invoice_created] => 1634467789
        [invoice_expires] => 1634469589
        [invoice_amount] => 10
    )

How do I store $_POST values only (not keys) separated by & in form of a string like the one below:

Will this work

echo implode("&",$_POST);

Output example:

ece6ba4ec435986db93924d070b4c13b&1772fb6eafda04ceb11c77cf719a347f&1634467789&1634469589&10

CodePudding user response:

Use implode() and set & as the separator:

$string = implode('&', $_POST);

CodePudding user response:

You can use the built-in function of PHP array_values() to get only the values from the $_POST array. Then, use the built in function implode, to combine the whole array into one string seprated by & sign.

$values = array_values($_POST);
$string_values = implode("&",$values);
  •  Tags:  
  • php
  • Related