Can I make the contents of my array all lowercase? [duplicate] - php

This question already has answers here:
How to convert array values to lowercase in PHP?
(10 answers)
Closed 5 years ago.
I have this array and I'm currently researching on how to make the contents of the output lowercase.
foreach ($city_info['links'] as $bikes => $url) {
echo '<span> '.$bikes.'</span>';
}

echo '<span> '. strtolower($bikes) .'</span>';
https://www.w3schools.com/php/func_string_strtolower.asp

Related

How can i remove duplicate object from my array in php? [duplicate]

This question already has answers here:
array_unique for objects?
(15 answers)
PHP Removing duplicate objects from array
(3 answers)
Remove objects with duplicate values in array of stdClass objects
(3 answers)
Closed 4 months ago.
here I need to remove the same week id object array from my main array in PHP
[{"week_id":""},
{"week_id":"23","location_schedule":"Tuesday","location_date_from":"10\/18\/2022 4:30 PM"},
{"week_id":"23","location_schedule":"Tuesday","location_date_from":"10\/18\/2022 4:30 PM"},
{"week_id":"24","location_schedule":"Tuesday","location_date_from":"10\/25\/2022 3:30 PM"},
{"week_id":"24","location_schedule":"Tuesday","location_date_from":"10\/25\/2022 3:30 PM"}]
$weeksArray = array(array("week_id"=>""));
$i=0;
foreach($orderweek as $weeks)
{
$weeksArray[]=[
'week_id'=>$weeks['week_id'],
'location_schedule'=>$weeks['location_schedule'],
'location_date_from'=>$weeks['location_date_from']
];
echo "<br>";
// }
$i++;
}
// $weeksArray = array(array("week_id"=>"25"));
echo json_encode($weeksArray);
You already tried array_unique()?
If not Put array_unique($weeksArray, SORT_REGULAR) before json_encode
Here is documentation.
https://www.php.net/manual/en/function.array-unique.php

How to do a for each from end of the array in PHP [duplicate]

This question already has answers here:
Iterate in reverse through an array with PHP - SPL solution?
(11 answers)
Closed 7 years ago.
How to do a "for each" from the end of an array in PHP ?
The end function can only return me one element http://php.net/manual/fr/function.end.php
Reverse the array and do a normal foreach?
$newArray = array_reverse($array);
foreach ($newArray as $key => $value) {
...
}

I need to split an url in php [duplicate]

This question already has answers here:
Using PHP to split a URL
(4 answers)
Closed 8 years ago.
if(isset($_SERVER['HTTP_REFERER'])) {
$sitio = $_SERVER['HTTP_REFERER'];
}
I need to split $sitio so i have "example" instead of "http://example.com/subfolder" or "http://www.example.com/subfolder"!
You can use parse_url.
if(isset($_SERVER['HTTP_REFERER'])) {
$sitio = parse_url($_SERVER['HTTP_REFERER'])['host'];
}

convert string to array and get value in php [duplicate]

This question already has answers here:
PHP string to array
(4 answers)
Closed 8 years ago.
I have a complete string how can i get some part of it and insert into an array this is my string in php
[{"albumid":"ASaBFzCtl8","albumname":"anni","type":"3","access":"2","itemcount":"2"},{"albumid":"EmgsZ43ehT","albumname":"testalbum","type":"1","access":"1","itemcount":"0"},{"albumid":"Jf4H4SvFGk","albumname":"test2album","type":"3","access":"1","itemcount":"0"},{"albumid":"k3pacBSmIl","albumname":"testalbumpvt","type":"3","access":"2","itemcount":"0"}]
i want something similar to this
$value1 = $array[0];
// {"albumid":"ASaBFzCtl8","albumname":"anni","type":"3","access":"2","itemcount":"2"}
is this possible to get each value like this
$value1 = $array[0]['albumid'];
// ASaBFzCtl8
Yes use json_decode()
$j = '[{"albumid":"ASaBFzCtl8","albumname":"anni","type":"3","access":"2","itemcount":"2"},{"albumid":"EmgsZ43ehT","albumname":"testalbum","type":"1","access":"1","itemcount":"0"},{"albumid":"Jf4H4SvFGk","albumname":"test2album","type":"3","access":"1","itemcount":"0"},{"albumid":"k3pacBSmIl","albumname":"testalbumpvt","type":"3","access":"2","itemcount":"0"}]';
$data = json_decode($j,true);
You can use loop to read the data as
foreach($data as $key=>$val){
echo $val["albumid"]."<br />";
}
Above will just get the albumid you can read whatever you want from this array.

How to add a prefix before an array [duplicate]

This question already has answers here:
Add a prefix to each item of a PHP array
(7 answers)
Closed 9 years ago.
I have an array in PHP:
$pbx01_connection = array("customer/voip_extensions.php");
how can i add a prefix and suffix to each item in the array?
for example,
$pbx01_connection = '/admin/'.array("customer/voip_extensions.php");
so /admin/ is added before each item in the array?
Use array_map():
<?php
function addPrefix($value)
{
return '/admin/' . $value
}
$new_array = array_map("addPrefix", $array);
print_r($new_array);
?>

Categories