|
Pointless Dribble
Okay This is another weird one from me, i want to thank OIS for helping me out on my last question... which deals with this same kind of funky array manipulation... i studied that code in depth and i feel it has helped me become better...
Started by youdontmeanmuch on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Function array_depth_count(&$array, $count=array(), $depth=1) { foreach ($array as &$value) { if (is_array($value)) { $value['count'] = ++$count[$depth]; array_depth_count($....
|
|
Hi
In PHP, will these always return the same values?
//example 1 $array = array(); if ($array) { echo 'the array has items'; } // example 2 $array = array(); if (count($array)) { echo 'the array has items'; }
Thank you!
Started by alex on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
See also: http://ca2.php.net/manual/enFrom http://www.php.net/manual/en/language.types.boolean.php , it says that an empty array" an array with zero elements an....
And the count of an array is true with more than one element.
|
|
I am having trouble counting the unique values in an array, and I need to do so without rearranging the array elements.
How can I accomplish this?
Started by jarus on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
MyArray.Distinct().Count();
Non LINQ:
List<int> uniqueValues = new List<int>(); for(int i = 0; i < array = new int[] { 1, 2, 3, 3, 3, 4 }; // .Net 3.0 - use Dictionary<int, bool> // .Net 1.1 - use Hashtable var set....
|
Ask your Facebook Friends
|
HI,
I am looking at this bit of code:
var length = 0; for (recordId in publicationTableIndexes[sortColumnNumber]){ length++; }
And I am wondering if there is a way of getting the same result without the loop?
publicationTableIndexes is an array containing...
Started by flavour404 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The data stored.
What i would do is get);
That will show you the entire contents of the array, and you can see what is exactly in it.
Sounds like the data in the array is not what your expecting it to be.
|
|
Say I have an array like this:
$array = array('', '', 'other', '', 'other');
How can I count the number with a given value (in the example blank)?
And do it efficiently? (for about a dozen arrays with hundreds of elements each) This example times out ...
Started by Tom on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
$myArray = array("", "", "other", "", "other"); $length = count(array_keys($myArray, ""));
I dont know if this would be faster but it's something to try:
foreach($array....
Then count the result.
Specifies a search-value.
|
|
Hi all,
i have foreach, which generate following arrays:
==== array 1 ==== array 0 => array 'tag' => string 'daf' (length=3) 1 => array 'tag' => string 'daa' (length=3) 2 => array 'tag' => string 'daf' (length=3) 3 => array 'tag' ...
Started by cupakob on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Var_export( array_count_valuesSomething a bit like this should work:
$result = array(); foreach (array_merge($array1, $array2( call_user_func_....
Here is another code.
]++; }
Did not notice it was 2 dimensional array.
|
|
How to remove duplicate values from an array in PHP and count the occurrence of every element? I have this array
foo bar foo I want the result to be in array like this
value freq ---- ---- foo 2 bar 1
Thanks
Started by ahmed on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
$arr = array('foo','bar','foo'); print_r(array_count_values($arr)); $arr = array_unique($arr); print_r($arr);
gives:
Array
....
]++; }
You want array_count_values() , followed by an array_unique() .
|
|
I'm trying to merge these 2 arrays
$arr1 = array('a' => "1", 'b' => "2", 'c' => "3"); $arr2 = array('a' => "9", 'b' => "8", 'd' => "7");
into an array that looks like this
$arr1 = array( 'a' => array("1", "9"), 'b' => array("2"...
Started by drummer on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
array_keys($keys); $values = array_pad(array(), count($keys), array()); $ret = array_combine($keys = array_pad(array(), count($keys), array()); $ret = array_combine($keys,....
|
|
How can I count the number of elements in an array, because contrary to logic array.count(string) does not count all the elements in the array, it just searches for the number of occurrences of string.
Started by Unkwntech on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Functions encased....
Len(myArray)
Or,
myArray.__len__()
if you want to be oopy; "len(myArray)" is a lot easier to type! :)
len is a built-in function that calls the given container object's __len__ member function to get the number of elements in the object .
|
|
Hi all, I'm trying to count all the values inside an array, I've tried using count() but to no avail, the array values may also have negatives in them, example:
Array ( [name] => 1 [phone] => 1 [emailX] => 1 [car] => 0 [finance] => 2 [employed...
Started by SoulieBaby on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
count will return the number of elements, you will want to use array_sum
$sum = array....
You can use array_sum() :
$sum = array_sum($myArray);
The count() function gives you the number of items in the array.
|