array_count_values Problem
am 12.01.2010 15:09:45 von Alice Wei
--_6a16cfa5-cf81-45a8-96a9-0d9f3349199e_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
I have a code in the following=2C after investigating more closely on how=
to use array_count_values():
//Calculate the number of elements in array
$total_num =3D count($friend_from)=3B
$total_num2 =3D count(array_unique($friend_from))=3B
for ($i=3D0=3B$i<=3D$total_num2=3B$i++) echo $friend_from[$i] . " " . array=
_count_values($friend_from[$i]) . "\n"=3B
Neither of these two numbers=2C $total_num and $total_num2 are 0=2C but I=
only get something like this:
Monroe=2C IN=20
Cherokee=2C OK=20
Cherokee=2C OK=20
Cleveland=2C OK=20
Greer=2C OK=20
How come that I cannot get it to print out the individual array_count_val=
ues? Have I missed something here?
Thanks for your help.=20
=20
____________________________________________________________ _____
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/196390707/direct/01/=
--_6a16cfa5-cf81-45a8-96a9-0d9f3349199e_--
Re: array_count_values Problem
am 12.01.2010 17:17:57 von Jonathan Tapicer
Hi,
The function array_count_values returns an array
(http://php.net/array_count_values). So you are using it the wrong
way, you should assign the return value to a variable and then access
some index.
Regards,
Jonathan
On Tue, Jan 12, 2010 at 11:09 AM, Alice Wei wrote:
>
> Hi,
>
> =A0I have a code in the following, after investigating more closely on ho=
w to use array_count_values():
>
> =A0//Calculate the number of elements in array
> $total_num =3D count($friend_from);
> $total_num2 =3D count(array_unique($friend_from));
> for ($i=3D0;$i<=3D$total_num2;$i++) echo $friend_from[$i] . " " . array_c=
ount_values($friend_from[$i]) . "\n";
>
> =A0Neither of these two numbers, $total_num and $total_num2 are 0, but I =
only get something like this:
>
> Monroe, IN
> Cherokee, OK
> Cherokee, OK
> Cleveland, OK
> Greer, OK
> =A0How come that I cannot get it to print out the individual array_count_=
values? Have I missed something here?
> =A0Thanks for your help.
>
>
> ____________________________________________________________ _____
> Hotmail: Trusted email with powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/196390707/direct/01/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: array_count_values Problem
am 12.01.2010 19:17:35 von Alice Wei
--_45d46ece-2978-4f39-8c36-ac84e74313e0_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
Thanks for the replies.=20
Turns out that I can assign a variable $array_count =3D array_count_value=
s($friend_from)=2C and I accessed the individual values by doing=20
for ($i=3D0=3B$i<$total_num=3B$i++) {
$friend_location =3D $friend_from[$i]=3B =20
$count_friend =3D $array_count[$friend_location]=3B =20
echo $count_friend . "\n"=3B =20
}
Thanks again.=20
Alice
> Date: Tue=2C 12 Jan 2010 13:17:57 -0300
> Subject: Re: [PHP] array_count_values Problem
> From: tapicer@gmail.com
> To: ajwei@alumni.iu.edu
> CC: php-general@lists.php.net
>=20
> Hi=2C
>=20
> The function array_count_values returns an array
> (http://php.net/array_count_values). So you are using it the wrong
> way=2C you should assign the return value to a variable and then access
> some index.
>=20
> Regards=2C
>=20
> Jonathan
>=20
> On Tue=2C Jan 12=2C 2010 at 11:09 AM=2C Alice Wei w=
rote:
> >
> > Hi=2C
> >
> > I have a code in the following=2C after investigating more closely on =
how to use array_count_values():
> >
> > //Calculate the number of elements in array
> > $total_num =3D count($friend_from)=3B
> > $total_num2 =3D count(array_unique($friend_from))=3B
> > for ($i=3D0=3B$i<=3D$total_num2=3B$i++) echo $friend_from[$i] . " " . a=
rray_count_values($friend_from[$i]) . "\n"=3B
> >
> > Neither of these two numbers=2C $total_num and $total_num2 are 0=2C bu=
t I only get something like this:
> >
> > Monroe=2C IN
> > Cherokee=2C OK
> > Cherokee=2C OK
> > Cleveland=2C OK
> > Greer=2C OK
> > How come that I cannot get it to print out the individual array_count_=
values? Have I missed something here?
> > Thanks for your help.
> >
> >
> > ____________________________________________________________ _____
> > Hotmail: Trusted email with powerful SPAM protection.
> > http://clk.atdmt.com/GBL/go/196390707/direct/01/
=20
____________________________________________________________ _____
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/196390710/direct/01/=
--_45d46ece-2978-4f39-8c36-ac84e74313e0_--