Tagged Questions
158
votes
5answers
93k views
Sort multidimensional Array by Value (2) [duplicate]
Possible Duplicate:
How do I sort a multidimensional array in php
How can I sort this array by the value of the "order" key? Even though the values are currently sequential, they will not ...
128
votes
10answers
25k views
PHP PDO: Can I bind an array to an IN() condition?
I'm curious to know if it's possible to bind an array of values to a placeholder using PDO. The use case here is attempting to pass an array of values for use with an IN() condition.
I'm not very ...
12
votes
22answers
3k views
PHP syntax for dereferencing function result
In every other programming language I use on a regular basis, it is simple to operate on the return value of a function without declaring a new variable to hold the function result.
In PHP, however, ...
29
votes
10answers
18k views
How to Flatten a Multidimensional Array?
Is it possible, in PHP, to flatten a (bi/multi)dimensional array without using recursion or references?
I'm only interested in the values so the keys can be ignored, I'm thinking in the lines of ...
312
votes
9answers
306k views
How to delete an element from an array in php?
Does anyone know an easy way to delete an element from a php array? So that foreach($array) no longer includes that element. I thought that setting it to null would do it, but apparently not.
22
votes
5answers
22k views
Sorting an associative array in PHP
I have an array in this format:
Array
(
[0] => Array
(
[text] => tests
[language] =>
[advertiserCompetitionScale] => 5
...
77
votes
19answers
81k views
43
votes
13answers
84k views
How to search by key=>value in a multidimensional array in PHP
Is there any fast way to get all subarrays where a key value pair was found in a multidimensional array? I can't say how deep the array will be.
Simple example array:
$arr = array(0 => ...
30
votes
6answers
27k views
How to remove duplicate values from a multi-dimensional array in PHP
How can I remove duplicate values from a multi-dimensional array in PHP?
Example array:
Array
(
[0] => Array
(
[0] => abc
[1] => def
)
[1] => Array
(
[0] => ...
17
votes
12answers
24k views
How to “flatten” a multi-dimensional array to simple one in PHP?
It's probably beginner question but I'm going through documentation for longer time already and I can't find any solution. I thought I could use implode for each dimension and then put those strings ...
177
votes
14answers
48k views
Preferred method to store PHP arrays (json_encode vs serialize)
I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in my web app but the vast ...
65
votes
7answers
108k views
PHP/MYSQL using an array in WHERE clause
given an array
$galleries = array
(
[0] => 1
[1] => 2
[2] => 5
)
I want to have a sql query that uses the values of the array in its ...
20
votes
4answers
10k views
Transposing multidimensional arrays in PHP
How would you flip 90 degrees (transpose) a multidimensional array in PHP? For example:
// Start with this array
$foo = array(
'a' => array(
1 => 'a1',
2 => 'a2',
3 ...
33
votes
7answers
11k views
PHP: Access Array Value on the Fly
in php, i often need to map a variable using an array ... but i can not seem to be able to do this in a one liner. c.f. example:
// the following results in an error:
echo array('a','b','c')[$key];
...
2
votes
3answers
1k views
Sorting a multidimensional array in PHP?
I have this kind of an array
array(5) {
[0]=>
array(5) {
[0]=>
string(7) "jannala"
[1]=>
string(10) "2009-11-16"
[2]=>
string(29) "
<p>Jotain ...