Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13161
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Filling an array with random input doesn't quite work |
| Date | 2014-03-16 09:46 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <lg4a05$dbe$1@dont-email.me> (permalink) |
| References | (1 earlier) <CYIUu.12650$%o4.7530@fx09.iad> <2311625.YxiY5vK2W4@PointedEars.de> <0.6b9d1a51aaf973162356.20140315213216GMT.8761nf5esf.fsf@bsb.me.uk> <lg31d6$ema$1@dont-email.me> <0.a23b5131e0d1a80cce9a.20140316025122GMT.87siqi500l.fsf@bsb.me.uk> |
On 3/15/2014 10:51 PM, Ben Bacarisse wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
>
>> On 3/15/2014 5:32 PM, Ben Bacarisse wrote:
>>> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>>>
>>>> Daniel Pitts wrote:
> <snip>
>>>>> for ($x = 1; $x < 40; ++$x) {
>>>>> $ayr[$x] = rand(60, 69);
>>>>> }
>>>>>
>>>>> So much simpler, more efficient, and actually correct.
>>>>
>>>> No, this will produce an array of only 39 elements, assuming there was not
>>>> already one. This can be easily fixed, of course.
>>>>
>>>> Still,
>>>>
>>>> $keys = range(1, 40);
>>>> $ayr = array_combine($keys, array_map(function () {
>>>> return rand(60, 69);
>>>> }, $keys)));
>>>>
>>>> is much more elegant :)
>>>
>>> Yes, but it's a shame about the extra ')'. I think
>>>
>>> $ayr = array_map(function () { return rand(60, 69); },
>>> array_fill(1, 40, null));
>>>
>>> is a little simpler.
>>>
>>
>> Shorter, maybe - but arguably NOT simpler. Hand that code to a new
>> PHP programmer and he/she will have no idea.
>
> Surely that would depend on their background would it not? Anyway, I
> meant simpler that the version using array_combine and array_map.
>
No, it does not. You may not be the only one looking at it.
>> It's generally better to code for clarity first.
>
> Yes, I agree, but clarity is not an absolute, and aiming to be clear to
> beginners puts considerable constraints on design and coding.
>
Not at all. But not being able to be clear in coding shows a lack of
good programming skills.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Filling an array with random input doesn't quite work richard <noreply@example.com> - 2014-03-12 13:18 -0400
Re: Filling an array with random input doesn't quite work Tim Streater <timstreater@greenbee.net> - 2014-03-12 17:36 +0000
Re: Filling an array with random input doesn't quite work Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-12 19:02 +0000
Re: Filling an array with random input doesn't quite work Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-12 19:06 +0000
Re: Filling an array with random input doesn't quite work Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-12 20:34 +0000
Re: Filling an array with random input doesn't quite work Tim Streater <timstreater@greenbee.net> - 2014-03-12 22:51 +0000
solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) richard <noreply@example.com> - 2014-03-12 17:08 -0400
Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Tim Streater <timstreater@greenbee.net> - 2014-03-12 22:49 +0000
Re: solved! Re: Filling an array with random input doesn't quite work Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-13 01:11 +0100
Re: solved! Re: Filling an array with random input doesn't quite work richard <noreply@example.com> - 2014-03-12 22:43 -0400
Re: solved! Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-14 23:23 +0100
Re: solved! Re: Filling an array with random input doesn't quite work Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-14 23:58 +0100
Re: solved! Re: Filling an array with random input doesn't quite work richard <noreply@example.com> - 2014-03-12 21:14 -0400
Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-13 02:50 +0000
Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-13 16:23 +0000
Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-13 02:53 +0000
Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-12 23:02 -0400
Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-12 23:11 -0400
Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-14 09:31 -0400
Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-14 11:00 -0400
Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-14 11:47 -0400
Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-14 12:55 -0400
Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-14 23:10 -0400
Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-13 00:31 -0400
Re: Filling an array with random input doesn't quite work Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-03-14 12:42 -0700
Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-14 23:07 +0100
Re: Filling an array with random input doesn't quite work Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-15 21:32 +0000
Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-15 23:14 +0100
Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-15 22:14 -0400
Re: Filling an array with random input doesn't quite work Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-16 02:51 +0000
Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-16 09:46 -0400
Re: Filling an array with random input doesn't quite work Gabriel Dragffy <usenet@moojuice.net> - 2014-03-16 14:45 +0000
Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-16 19:52 -0400
Re: Filling an array with random input doesn't quite work Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-17 02:16 +0000
Re: Filling an array with random input doesn't quite work Gabe <usenet@moojuice.net> - 2014-03-17 12:43 +0000
Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-17 08:52 -0400
Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-17 14:32 +0100
Re: Filling an array with random input doesn't quite work Gabe <usenet@moojuice.net> - 2014-03-17 13:47 +0000
Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-17 16:07 +0100
csiph-web