Multidimensional Array modify values

58 views Asked by At

I'd changed, the data in this line.

$fileConv = $_GET['file']; // It retrieves data to add.
$file = intval($fileConv); // Conversion

$ArrayNotes = array (
  0 => array ('titre' => 'aaa','ref' => 'aaa','date' => 'aaa','like' => aaa,'url' => 'aaa'),
  1 => array ('titre' => 'aaa1','ref' => 'aaa1','date' => 'aaa1','like' => aaa1,'url' => 'aaa1') // my array
);

$like = $ArrayNotes[$file]['like'] + 1; // The only data that changes.

$donnee = array("titre" => $ArrayNotes[$file]['titre'], "ref" => $ArrayNotes[$file]['ref'],"date" => $ArrayNotes[$file]['date'], "like" => $like, "url" => $ArrayNotes[$file]['url']); // Change Data

As stated, I want to know how to change this data directly.

Example : To add a new line :

array_push($ArrayNotes, $donnee);
$var_str = var_export($ArrayNotes, true);
$var = "<?php\n\n\$ArrayNotes = $var_str;\n\n?>";
file_put_contents('content.php', $var);

Thanks you for your help.

1

There are 1 answers

3
dieBeiden On BEST ANSWER

Should be as easy as the following:

$ArrayNotes[$file]['like'] = 1234;

And if you just wish to add one to the existing field, you may do:

$ArrayNotes[$file]['like'] += 1;