This question already has answers here:
How to remove duplicate values from an array in PHP
(26 answers)
Closed 3 years ago.
I have an array,
`Array
(
[0] => 2019-08-02
[1] => 2019-08-02
[2] => 2019-08-03
)`
I need to remove duplicates from this array.I tried converting strtotime and compared But not getting result.
Please help
Regards,
Rekha
You can just write the code like this:
$arr = array_unique($arr)
Hope this helps.
Related
This question already has answers here:
reformat an php array [duplicate]
(2 answers)
Closed 10 months ago.
I'm having following data:
Array ( [one] => this [two] => this2 )
Which I want to convert to json type which looks like:
data:{[one,this],[two,this2]}
How can I get through this in effecient manner?
Edit:
I've tried a lot of things This is actual data which I need to make datatable compatible:
{"draw":0,"recordsTotal":null,"recordsFiltered":null,"data":[[{"first":[""],"second":[""],"third":[""],"fourth":[""],"fifth":[""],"sixth":["value"]}]]}
as the data here is in key=>value form json is not compatible for datatables (PHP)
You can use array_map and array_keys:
$result = array_map(null, array_keys($array), $array);
$json = json_encode($result);
Here is working demo.
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 4 years ago.
I know this question sounds silly, and seems like a duplicate to the other questions, but I can almost assure you it is not a duplicate.
I am getting an issue from PHP:
Notice: Undefined index: content in FILE_PATH on line 21
Line 21: echo htmlentities($about['content']);
I know for sure that $about['content'] is set because for debugging, I have
print_r($about)
Which gives me
Array
(
[0] => Array
(
[id] => 1
[page] => About Us
[content] => I have stuff here.... content for test purpose.
)
)
Any help is appreciated.
Thanks
Edit
This question is not duplicate because all the answers to the other questions don't talk about array of array. Please do not mark this question as duplicate.
From your print_r looks like you need to correct the source, or use:
echo htmlentities($about[0]['content']);
The $about is an array of array that contains the content index. One of the solution is to use:
$about = $about[0]; // Only if you know that this is the only case.
The right way is to correct at the source, why it is not being a source array, but has another sub-array.
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
I have an array that holds a number of arrays. I access them in turn e.g.
print_r($orderData[0]) and the output is:
Array (
[201] => Array (
[name] => SuperMarket One
[type] => line_item
[item_meta] => Array (
[_qty] => Array (
[0] => 1
)
)
)
)
My issue is, I can't seem to access anything e.g. print_r($orderData[0]['name']) gives me:
Notice: Undefined index: name in /Path
Likewise, I can't use print_r($orderData[0][0]) etc.
I must be missing something quite obvious here.
You have another array in it with the key 201. Use PHP's function var_dump($orderData[0]) to view the complete structure of your array.
Access it using
$orderData[0][201]['name']
This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 7 years ago.
I've finally figured out how to fetch data from Google Analytics to website, unfortunately output (print_r) is PHP array inside an array:
Array ( [0] => Array ( [0] => 196 ) )
I need to get the number 196 & "save" it as variable in order to use it in calculations or output it, any ideas how to achieve this?
Im looking for overall solution/principle/rule because some data is even array inside array inside array etc.
you need to grab the first array element -position 0 - and from this inner array you pick the first element - also position 0 - which is 196, Check this: PHP Fiddle - hit run to execute
// getting 196
echo $myArr[0][0];
Use this:
$newVariable = $yourArray[0][0];
echo $newVariable; //This will echo the answer.
//This answer is self explanatory.
This question already has answers here:
Special characters in property name of object
(2 answers)
Closed 9 years ago.
When I do a print_r($this->info->artist->image[4]);, I get this:
stdClass Object
(
[#text] => http://userserve-ak.last.fm/serve/_/68145708/AWOLNATION+PNG.png
[size] => mega
)
How do I get the [#text] part?
You would do:
$this->info->artist->image[4]->{'#text'};
$this->info->artist->image[4]->{'#text'};