Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12305 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2013-12-19 13:41 -0500 |
| Last post | 2013-12-20 18:37 +0000 |
| Articles | 20 on this page of 26 — 13 participants |
Back to article view | Back to comp.lang.php
foreach problem part two richard <noreply@example.com> - 2013-12-19 13:41 -0500
Re: foreach problem part two Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-19 20:00 +0100
Re: foreach problem part two Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-19 19:16 +0000
Re: foreach problem part two The Natural Philosopher <tnp@invalid.invalid> - 2013-12-19 19:21 +0000
Re: foreach problem part two The Natural Philosopher <tnp@invalid.invalid> - 2013-12-19 19:20 +0000
Re: foreach problem part two Evan Platt <evan@theobvious.espphotography.com.invalid> - 2013-12-19 23:07 -0800
Re: foreach problem part two Scott Johnson <noonehome@chalupasworld.com> - 2013-12-20 00:59 -0800
fixed! (was: foreach problem part two) richard <noreply@example.com> - 2013-12-19 16:07 -0500
Re: fixed! (was: foreach problem part two) Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-20 18:48 +0000
Re: foreach problem part two Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-19 22:34 +0000
Re: foreach problem part two richard <noreply@example.com> - 2013-12-19 18:39 -0500
Re: foreach problem part two Jerry Stuckle <jstucklex@attglobal.net> - 2013-12-19 19:51 -0500
Re: foreach problem part two Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-20 02:09 +0100
Re: foreach problem part two richard <noreply@example.com> - 2013-12-19 23:05 -0500
Re: foreach problem part two Richard Damon <Richard@Damon-Family.org> - 2013-12-19 23:37 -0500
Re: foreach problem part two Norman Peelman <npeelman@cfl.rr.com> - 2013-12-20 07:14 -0500
Re: foreach problem part two Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-20 16:35 +0100
Re: foreach problem part two Norman Peelman <npeelman@cfl.rr.com> - 2013-12-20 07:11 -0500
Re: foreach problem part two Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-20 13:17 +0000
Re: foreach problem part two Evan Platt <evan@theobvious.espphotography.com.invalid> - 2013-12-20 09:14 -0800
Re: foreach problem part two Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-20 18:52 +0000
Re: foreach problem part two John Smith <johnsmithjsm@live.com> - 2014-01-06 23:13 -0500
Re: foreach problem part two Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-07 10:07 +0100
Re: foreach problem part two Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-20 03:11 +0000
Re: foreach problem part two Arno Welzel <usenet@arnowelzel.de> - 2013-12-20 07:52 +0100
Re: foreach problem part two Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-20 18:37 +0000
Page 1 of 2 [1] 2 Next page →
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-12-19 13:41 -0500 |
| Subject | foreach problem part two |
| Message-ID | <oib4w8z2sr5y$.15xxzxjds0xb0$.dlg@40tude.net> |
<?php
foreach ($aname as $item){
echo $aname[$item][1];
echo " (".$aname[$item][2].")";
}
?>
I decided to create a second array that holds only the artist and number of
records.
So why am I getting "invalid argument" with this?
[toc] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-12-19 20:00 +0100 |
| Message-ID | <52b34253$0$9521$9b4e6d93@newsspool1.arcor-online.net> |
| In reply to | #12305 |
Am 19.12.2013 19:41, schrieb richard:
> <?php
> foreach ($aname as $item){
> echo $aname[$item][1];
> echo " (".$aname[$item][2].")";
> }
> ?>
>
> I decided to create a second array that holds only the artist and number of
> records.
> So why am I getting "invalid argument" with this?
You may consider reading the manual:
<http://www.php.net/manual/en/control-structures.foreach.php>.
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-12-19 19:16 +0000 |
| Message-ID | <l8vglu$hhm$2@dont-email.me> |
| In reply to | #12307 |
On Thu, 19 Dec 2013 20:00:41 +0100, Christoph Michael Becker wrote: > You may consider reading the manual: > <http://www.php.net/manual/en/control-structures.foreach.php>. I suspect the reason richard doesn't read the manual is because it's full of big scary words like parameter, integer and boolean that he doesn't understand. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-12-19 19:21 +0000 |
| Message-ID | <l8vgvd$hpv$4@news.albasani.net> |
| In reply to | #12309 |
On 19/12/13 19:16, Denis McMahon wrote: > On Thu, 19 Dec 2013 20:00:41 +0100, Christoph Michael Becker wrote: > >> You may consider reading the manual: >> <http://www.php.net/manual/en/control-structures.foreach.php>. > > I suspect the reason richard doesn't read the manual is because it's full > of big scary words like parameter, integer and boolean that he doesn't > understand. > I am not convinced he can read at all. -- Ineptocracy (in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-12-19 19:20 +0000 |
| Message-ID | <l8vgu5$hpv$3@news.albasani.net> |
| In reply to | #12307 |
On 19/12/13 19:00, Christoph Michael Becker wrote:
> Am 19.12.2013 19:41, schrieb richard:
>> <?php
>> foreach ($aname as $item){
>> echo $aname[$item][1];
>> echo " (".$aname[$item][2].")";
>> }
>> ?>
>>
>> I decided to create a second array that holds only the artist and number of
>> records.
>> So why am I getting "invalid argument" with this?
>
> You may consider reading the manual:
> <http://www.php.net/manual/en/control-structures.foreach.php>.
>
IF I had £5 for every time someone has suggested richard reads the
manaul THEN I'd be able to afford a new computer.
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | Evan Platt <evan@theobvious.espphotography.com.invalid> |
|---|---|
| Date | 2013-12-19 23:07 -0800 |
| Message-ID | <u4r7b9h3i3ap2klbqmpd61eae0vdo7vsh0@4ax.com> |
| In reply to | #12307 |
On Thu, 19 Dec 2013 20:00:41 +0100, Christoph Michael Becker <cmbecker69@arcor.de> wrote: >You may consider reading the manual: ><http://www.php.net/manual/en/control-structures.foreach.php>. Why bother when he's got hundreds of free experts at his disposal to write his website for him here -- To reply via e-mail, remove The Obvious and .invalid from my e-mail address.
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-12-20 00:59 -0800 |
| Message-ID | <l910sr$m5s$1@dont-email.me> |
| In reply to | #12324 |
On 12/19/2013 11:07 PM, Evan Platt wrote: > On Thu, 19 Dec 2013 20:00:41 +0100, Christoph Michael Becker > <cmbecker69@arcor.de> wrote: > >> You may consider reading the manual: >> <http://www.php.net/manual/en/control-structures.foreach.php>. > > Why bother when he's got hundreds of free experts at his disposal to > write his website for him here > Hey everyone needs a hobby. ;)
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-12-19 16:07 -0500 |
| Subject | fixed! (was: foreach problem part two) |
| Message-ID | <1e8mzc65nipg6.462wx2z9sb3n.dlg@40tude.net> |
| In reply to | #12305 |
On Thu, 19 Dec 2013 13:41:51 -0500, richard wrote:
> <?php
> foreach ($aname as $item){
> echo $aname[$item][1];
> echo " (".$aname[$item][2].")";
> }
> ?>
>
> I decided to create a second array that holds only the artist and number of
> records.
> So why am I getting "invalid argument" with this?
<?php
$result=count($art60);
$acount=0;
while ($acount<=$result){
echo "<div class='blu'>";
$number=count($art60[$acount]);
echo $art60[$acount][0];
echo " (".$number.")";
echo "</div>";
$acount++;
}
?>
This version not only shows the names, but the number of songs each
produced as well.
http://mroldies.net/artists/60artists.php
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-12-20 18:48 +0000 |
| Subject | Re: fixed! (was: foreach problem part two) |
| Message-ID | <l923e3$d0q$2@dont-email.me> |
| In reply to | #12314 |
On Thu, 19 Dec 2013 16:07:52 -0500, richard wrote:
> This version not only shows the names, but the number of songs each
> produced as well.
What you actually wanted to do was something like this:
foreach($art60 as $tmp)echo"<div class='blu'>{$tmp[0]} (".count
($tmp).")</div>";
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Doug Miller <doug_at_milmac_dot_com@example.com> |
|---|---|
| Date | 2013-12-19 22:34 +0000 |
| Message-ID | <XnsA29BB28C4C683dougmilmaccom@78.46.70.116> |
| In reply to | #12305 |
richard <noreply@example.com> wrote in news:oib4w8z2sr5y$.15xxzxjds0xb0$.dlg@
40tude.net:
> <?php
> foreach ($aname as $item){
> echo $aname[$item][1];
> echo " (".$aname[$item][2].")";
> }
> ?>
>
> I decided to create a second array that holds only the artist and number of
> records.
> So why am I getting "invalid argument" with this?
Because you don't understand how foreach() works. RTFM.
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-12-19 18:39 -0500 |
| Message-ID | <y1yigdragnyw$.c2kv48q50osj.dlg@40tude.net> |
| In reply to | #12315 |
On Thu, 19 Dec 2013 22:34:24 +0000 (UTC), Doug Miller wrote:
> richard <noreply@example.com> wrote in news:oib4w8z2sr5y$.15xxzxjds0xb0$.dlg@
> 40tude.net:
>
>> <?php
>> foreach ($aname as $item){
>> echo $aname[$item][1];
>> echo " (".$aname[$item][2].")";
>> }
>> ?>
>>
>> I decided to create a second array that holds only the artist and number of
>> records.
>> So why am I getting "invalid argument" with this?
>
> Because you don't understand how foreach() works. RTFM.
I did.
There is a flaw in the works that is not discussed.
That being, it won't work with brackted arrays.
Works fine with standard arrays.
While (){}. however works and could care less which is used.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-12-19 19:51 -0500 |
| Message-ID | <l904am$qoa$1@dont-email.me> |
| In reply to | #12316 |
On 12/19/2013 6:39 PM, richard wrote:
> On Thu, 19 Dec 2013 22:34:24 +0000 (UTC), Doug Miller wrote:
>
>> richard <noreply@example.com> wrote in news:oib4w8z2sr5y$.15xxzxjds0xb0$.dlg@
>> 40tude.net:
>>
>>> <?php
>>> foreach ($aname as $item){
>>> echo $aname[$item][1];
>>> echo " (".$aname[$item][2].")";
>>> }
>>> ?>
>>>
>>> I decided to create a second array that holds only the artist and number of
>>> records.
>>> So why am I getting "invalid argument" with this?
>>
>> Because you don't understand how foreach() works. RTFM.
>
> I did.
> There is a flaw in the works that is not discussed.
> That being, it won't work with brackted arrays.
> Works fine with standard arrays.
>
> While (){}. however works and could care less which is used.
>
What do you mean by "bracketed arrays"? There is no such thing!
foreach() works fine with ANY array.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-12-20 02:09 +0100 |
| Message-ID | <52b398d2$0$9503$9b4e6d93@newsspool1.arcor-online.net> |
| In reply to | #12316 |
richard wrote:
> There is a flaw in the works that is not discussed.
> That being, it won't work with brackted arrays.
> Works fine with standard arrays.
Nonsense. PHP has only one array type.[1]
> While (){}. however works and could care less which is used.
Assume, you have an array:
$array = array('one', 'two', 'three');
Now you want to echo its elements in order. What is simpler and more
readable?
$i = 0;
while ($i < count($array)) {
echo $array[$i];
}
or
foreach ($array as $element) {
echo $element;
}
Additionally, the foreach loop is most likely faster.
[1] <http://www.php.net/manual/en/language.types.array.php>
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-12-19 23:05 -0500 |
| Message-ID | <t6ds31so68b7.1s80a7lxre6po$.dlg@40tude.net> |
| In reply to | #12318 |
On Fri, 20 Dec 2013 02:09:46 +0100, Christoph Michael Becker wrote:
> richard wrote:
>
>> There is a flaw in the works that is not discussed.
>> That being, it won't work with brackted arrays.
>> Works fine with standard arrays.
>
> Nonsense. PHP has only one array type.[1]
>
>> While (){}. however works and could care less which is used.
>
> Assume, you have an array:
>
> $array = array('one', 'two', 'three');
>
> Now you want to echo its elements in order. What is simpler and more
> readable?
>
> $i = 0;
> while ($i < count($array)) {
> echo $array[$i];
> }
>
> or
>
> foreach ($array as $element) {
> echo $element;
> }
>
> Additionally, the foreach loop is most likely faster.
>
> [1] <http://www.php.net/manual/en/language.types.array.php>
As you and others so kindly keep repeating, RTFM!
$array[0][0]="data"
Is 100% valid!
In the arrays manual, it shows the use of bracketed arrays several times.
So why don't you tell them they are wrong?
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2013-12-19 23:37 -0500 |
| Message-ID | <2QPsu.177440$4q1.100708@en-nntp-12.dc1.easynews.com> |
| In reply to | #12321 |
On 12/19/13, 11:05 PM, richard wrote:
> On Fri, 20 Dec 2013 02:09:46 +0100, Christoph Michael Becker wrote:
>
>> richard wrote:
>>
>>> There is a flaw in the works that is not discussed.
>>> That being, it won't work with brackted arrays.
>>> Works fine with standard arrays.
>>
>> Nonsense. PHP has only one array type.[1]
>>
>>> While (){}. however works and could care less which is used.
>>
>> Assume, you have an array:
>>
>> $array = array('one', 'two', 'three');
>>
>> Now you want to echo its elements in order. What is simpler and more
>> readable?
>>
>> $i = 0;
>> while ($i < count($array)) {
>> echo $array[$i];
>> }
>>
>> or
>>
>> foreach ($array as $element) {
>> echo $element;
>> }
>>
>> Additionally, the foreach loop is most likely faster.
>>
>> [1] <http://www.php.net/manual/en/language.types.array.php>
>
> As you and others so kindly keep repeating, RTFM!
>
> $array[0][0]="data"
>
> Is 100% valid!
>
> In the arrays manual, it shows the use of bracketed arrays several times.
> So why don't you tell them they are wrong?
>
As far as I can tell, the PHP Manual NEVER calls this a "bracketed
array", and an array created this way is indistinguishable (after
creation) from the array created with the array() operator.
Creating a previously non-existent member by this member in a previously
created array does have some advantages.
I will also note, that you original program had no line like this (at
least that you showed us).
[toc] | [prev] | [next] | [standalone]
| From | Norman Peelman <npeelman@cfl.rr.com> |
|---|---|
| Date | 2013-12-20 07:14 -0500 |
| Message-ID | <l91car$jg8$1@dont-email.me> |
| In reply to | #12322 |
On 12/19/2013 11:37 PM, Richard Damon wrote:
> On 12/19/13, 11:05 PM, richard wrote:
>> On Fri, 20 Dec 2013 02:09:46 +0100, Christoph Michael Becker wrote:
>>
>>> richard wrote:
>>>
>>>> There is a flaw in the works that is not discussed.
>>>> That being, it won't work with brackted arrays.
>>>> Works fine with standard arrays.
>>>
>>> Nonsense. PHP has only one array type.[1]
>>>
>>>> While (){}. however works and could care less which is used.
>>>
>>> Assume, you have an array:
>>>
>>> $array = array('one', 'two', 'three');
>>>
>>> Now you want to echo its elements in order. What is simpler and more
>>> readable?
>>>
>>> $i = 0;
>>> while ($i < count($array)) {
>>> echo $array[$i];
>>> }
>>>
>>> or
>>>
>>> foreach ($array as $element) {
>>> echo $element;
>>> }
>>>
>>> Additionally, the foreach loop is most likely faster.
>>>
>>> [1] <http://www.php.net/manual/en/language.types.array.php>
>>
>> As you and others so kindly keep repeating, RTFM!
>>
>> $array[0][0]="data"
>>
>> Is 100% valid!
>>
>> In the arrays manual, it shows the use of bracketed arrays several times.
>> So why don't you tell them they are wrong?
>>
>
> As far as I can tell, the PHP Manual NEVER calls this a "bracketed
> array", and an array created this way is indistinguishable (after
> creation) from the array created with the array() operator.
>
> Creating a previously non-existent member by this member in a previously
> created array does have some advantages.
>
> I will also note, that you original program had no line like this (at
> least that you showed us).
>
This is not 100% legal syntax because the second [0] acts as a string
offset instead of an index:
$alist[0][0] = "data";
Fatal error: Cannot use string offset as an array... you must use
*array()* to set these up.
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-12-20 16:35 +0100 |
| Message-ID | <1895038.mY5GtRscxT@PointedEars.de> |
| In reply to | #12330 |
Norman Peelman wrote:
> This is not 100% legal syntax because the second [0] acts as a string
> offset instead of an index:
>
> $alist[0][0] = "data";
> Fatal error: Cannot use string offset as an array... you must use
> *array()* to set these up.
Unsurprisingly, utter nonsense from you again.
$ php -r '$a[0] = 42; var_dump($a["0"]);'
int(42)
In fact,
$alist[0][0] = "data";
is equivalent to
$alist = array(array("data"));
or
$alist = array(0 => array("data"));
or
$alist = array(array(0 => "data"));
or
$alist = array(0 => array(0 => "data"));
or variations of that where the key is the string '0' or "0", if $alist did
not exist before.
It is equivalent to
$alist[0] = array("data");
and variations of that, including those where the keys are '0', if $alist
existed before but did not have an element with key 0.
And it is equivalent to itself if $alist[0] referred to an array before
(i.e., it modifies the element with index 0 of the array that is the element
with index 0 of the outer array).
That you can create „multi-dimensional“ arrays, which can even be
associative, with just one line, is the beauty of PHP.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
[toc] | [prev] | [next] | [standalone]
| From | Norman Peelman <npeelman@cfl.rr.com> |
|---|---|
| Date | 2013-12-20 07:11 -0500 |
| Message-ID | <l91c4q$ikt$1@dont-email.me> |
| In reply to | #12321 |
On 12/19/2013 11:05 PM, richard wrote:
> On Fri, 20 Dec 2013 02:09:46 +0100, Christoph Michael Becker wrote:
>
>> richard wrote:
>>
>>> There is a flaw in the works that is not discussed.
>>> That being, it won't work with brackted arrays.
>>> Works fine with standard arrays.
>>
>> Nonsense. PHP has only one array type.[1]
>>
>>> While (){}. however works and could care less which is used.
>>
>> Assume, you have an array:
>>
>> $array = array('one', 'two', 'three');
>>
>> Now you want to echo its elements in order. What is simpler and more
>> readable?
>>
>> $i = 0;
>> while ($i < count($array)) {
>> echo $array[$i];
>> }
>>
>> or
>>
>> foreach ($array as $element) {
>> echo $element;
>> }
>>
>> Additionally, the foreach loop is most likely faster.
>>
>> [1] <http://www.php.net/manual/en/language.types.array.php>
>
> As you and others so kindly keep repeating, RTFM!
>
> $array[0][0]="data"
>
> Is 100% valid!
>
> In the arrays manual, it shows the use of bracketed arrays several times.
> So why don't you tell them they are wrong?
>
Then maybe you should read it again, specifically "Creating/modifying
with square bracket syntax". That tells you why it isn't working.
However:
$year = "60";
$alist = "art".$year;
$$alist = array(0 => array(0 => "00", 1 => "01"), 1 => array(0 => "10",
1 => "11"));
...is a small example of what you are trying to do.
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[toc] | [prev] | [next] | [standalone]
| From | Doug Miller <doug_at_milmac_dot_com@example.com> |
|---|---|
| Date | 2013-12-20 13:17 +0000 |
| Message-ID | <XnsA29C5425FEBD1dougmilmaccom@78.46.70.116> |
| In reply to | #12321 |
richard <noreply@example.com> wrote in news:t6ds31so68b7.1s80a7lxre6po$.dlg@ 40tude.net: > $array[0][0]="data" > > Is 100% valid! > > In the arrays manual, it shows the use of bracketed arrays several times. > So why don't you tell them they are wrong? The problem isn't your array notation, the problem is your misunderstanding of how foreach() works. RTFM.
[toc] | [prev] | [next] | [standalone]
| From | Evan Platt <evan@theobvious.espphotography.com.invalid> |
|---|---|
| Date | 2013-12-20 09:14 -0800 |
| Message-ID | <hmu8b950vr4rimd4g2pdqao87h6h11ht5c@4ax.com> |
| In reply to | #12321 |
On Thu, 19 Dec 2013 23:05:59 -0500, richard <noreply@example.com> wrote: >As you and others so kindly keep repeating, RTFM! > >$array[0][0]="data" > >Is 100% valid! > >In the arrays manual, it shows the use of bracketed arrays several times. >So why don't you tell them they are wrong? Why don't you submit it as a bug if you're so confident you're right, bullis? Then show us the bug link. Please. This should be good. -- To reply via e-mail, remove The Obvious and .invalid from my e-mail address.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.php
csiph-web