Answer the question
In order to leave comments, you need to log in
How to update data in an associative array of arrays?
In general, the essence is to come json array inside which there are arrays and they are also arrays.
It is necessary to replace each link of the nested array and return json back
. I do this:
foreach ($pays as $ke => &$va) {
$avatar = (array)$va;
foreach ($avatar as $key => &$value) {
if($key == "avatar" or $key == "flag"){
$path = $_SERVER['DOCUMENT_ROOT'].dirname(parse_url($value)['path'])."/";
$file = basename(parse_url($value)['path']);
if(!is_dir($path)){
mkdir($path, 0777, true);
}
if(is_dir($path)){
file_put_contents($path.$file, file_get_contents($value));
$newpath = dirname(parse_url($value)['path'])."/".$file;
$value = $newpath;
}
$newpath = dirname(parse_url($value)['path'])."/".$file;
$value = $newpath;
}
}
}
Answer the question
In order to leave comments, you need to log in
I answer myself:
foreach ($pays as $ke => &$va) {
$avatar = (array)$va;
foreach ($avatar as $key => &$value) {
if($key == "avatar" or $key == "flag"){
$path = $_SERVER['DOCUMENT_ROOT'].dirname(parse_url($value)['path'])."/";
$file = basename(parse_url($value)['path']);
/*if(!is_dir($path)){
mkdir($path, 0777, true);
}
if(is_dir($path)){
file_put_contents($path.$file, file_get_contents($value));
$newpath = dirname(parse_url($value)['path'])."/".$file;
$value = $newpath;
}*/
$newpath = dirname(parse_url($value)['path'])."/".$file;
$value = $newpath;
echo "<br>$value";
}
}
$va = $avatar;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question