-1

i would to use file_put_contents($filename, $data) but i have to add a bidimensional array and a variable:

$array= array(
   array("a","a"),
   array("b","b")
  );

$variable= 1;

How can i add them in $data ?

Is possible to do this by not adding both in a string ?

Thanks a lot and sorry for my english

Borja
  • 3,359
  • 7
  • 33
  • 66

1 Answers1

2
 $newArray = ['array' => $array, 'variable' => $variable];
 file_put_contents($filename, var_export($newArray, true));
  1. $data should be a string, you need to convert array to string.

  2. var_export would outputs or returns a parsable string representation of a variable.

Razon Yang
  • 420
  • 3
  • 10
  • i don't understand :( how can i add BOTH (array and variable) in $data ? – Borja Jun 30 '17 at 01:33
  • @Borja I have updated my answer. The `$data` should be a string, so you can only convert your `array` and `variable` to a string. – Razon Yang Jun 30 '17 at 01:59