php-general Digest 1 Mar 2011 16:03:20 -0000 Issue 7205

Topics (messages 311597 through 311607):

Sorting an array
        311597 by: Ron Piggott
        311599 by: Simon J Welsh
        311605 by: David Robley
        311606 by: FeIn
        311607 by: Jim Lucas

Implementing strict types
        311598 by: Paul McGarry
        311604 by: Richard Quadling

Re: very quick Regex query
        311600 by: David Hutto
        311601 by: David Hutto
        311602 by: Ashley Sheridan
        311603 by: Richard Quadling

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
I need help to know how to sort the words / phrases in my array.

Variable name: $words_used
print_r( $words_used ); Current output: Array ( [187] => Sin [249] => Punished 
[98] => Sanctuary [596] => Sing [362] => Anointing Oil )
Desired result: Alphabetical sort: Array ( [362] => Anointing Oil [249] => 
Punished [98] => Sanctuary [187] => Sin [596] => Sing ) 

The #’s are the auto_increment value of the word in the mySQL database.  The 
number is not representative of alphabetical order, but the order it was added 
to the database.

Thank you for your assistance.

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info  

--- End Message ---
--- Begin Message ---
On 1/03/2011, at 4:52 PM, Ron Piggott wrote:

> 
> I need help to know how to sort the words / phrases in my array.
> 
> Variable name: $words_used
> print_r( $words_used ); Current output: Array ( [187] => Sin [249] => 
> Punished [98] => Sanctuary [596] => Sing [362] => Anointing Oil )
> Desired result: Alphabetical sort: Array ( [362] => Anointing Oil [249] => 
> Punished [98] => Sanctuary [187] => Sin [596] => Sing ) 
> 
> The #’s are the auto_increment value of the word in the mySQL database.  The 
> number is not representative of alphabetical order, but the order it was 
> added to the database.
> 
> Thank you for your assistance.
> 
> Ron
> 
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info  

Have a look at asort() (http://php.net/asort), which is used to sort arrays but 
maintain the key association. The default search option should work fine for 
you, if not try one of the other SORT_* flags described on the sort() manual 
page.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--- End Message ---
--- Begin Message ---
Ron Piggott wrote:

> 
> I need help to know how to sort the words / phrases in my array.
> 
> Variable name: $words_used
> print_r( $words_used ); Current output: Array ( [187] => Sin [249] =>
> Punished [98] => Sanctuary [596] => Sing [362] => Anointing Oil ) Desired
> result: Alphabetical sort: Array ( [362] => Anointing Oil [249] =>
> Punished [98] => Sanctuary [187] => Sin [596] => Sing )
> 
> The #?s are the auto_increment value of the word in the mySQL database. 
> The number is not representative of alphabetical order, but the order it
> was added to the database.
> 
> Thank you for your assistance.
> 
> Ron

Like the man said - asort. May I recommend you to http://php.net where you
will find the answer to most of your queries, simply by looking under a
generic area, such as array (http://php.net/array) for this particular
problem. Surely you have been around here long enough to be able to find
things in the documentation, or at least try there first, by now?




Cheers
-- 
David Robley

Do fish get thirsty?
Today is Setting Orange, the 60th day of Chaos in the YOLD 3177. 


--- End Message ---
--- Begin Message ---
Also check http://www.php.net/manual/en/function.natsort.php

On Tue, Mar 1, 2011 at 1:39 PM, David Robley <robl...@aapt.net.au> wrote:

> Ron Piggott wrote:
>
> >
> > I need help to know how to sort the words / phrases in my array.
> >
> > Variable name: $words_used
> > print_r( $words_used ); Current output: Array ( [187] => Sin [249] =>
> > Punished [98] => Sanctuary [596] => Sing [362] => Anointing Oil ) Desired
> > result: Alphabetical sort: Array ( [362] => Anointing Oil [249] =>
> > Punished [98] => Sanctuary [187] => Sin [596] => Sing )
> >
> > The #?s are the auto_increment value of the word in the mySQL database.
> > The number is not representative of alphabetical order, but the order it
> > was added to the database.
> >
> > Thank you for your assistance.
> >
> > Ron
>
> Like the man said - asort. May I recommend you to http://php.net where you
> will find the answer to most of your queries, simply by looking under a
> generic area, such as array (http://php.net/array) for this particular
> problem. Surely you have been around here long enough to be able to find
> things in the documentation, or at least try there first, by now?
>
>
>
>
> Cheers
> --
> David Robley
>
> Do fish get thirsty?
> Today is Setting Orange, the 60th day of Chaos in the YOLD 3177.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On 2/28/2011 7:52 PM, Ron Piggott wrote:
> 
> I need help to know how to sort the words / phrases in my array.
> 
> Variable name: $words_used
> print_r( $words_used ); Current output: Array ( [187] => Sin [249] => 
> Punished [98] => Sanctuary [596] => Sing [362] => Anointing Oil )
> Desired result: Alphabetical sort: Array ( [362] => Anointing Oil [249] => 
> Punished [98] => Sanctuary [187] => Sin [596] => Sing ) 
> 
> The #’s are the auto_increment value of the word in the mySQL database.  The 
> number is not representative of alphabetical order, but the order it was 
> added to the database.
> 
> Thank you for your assistance.
> 
> Ron
> 
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info  
> 

Besides the answer others have pointed you to, I would recommend doing it in 
mysql?

SELECT * FROM <table> ORDER BY <your_column>;

Check out the syntax for it here.

http://dev.mysql.com/doc/refman/5.0/en/select.html
and
http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html

Jim Lucas

--- End Message ---
--- Begin Message ---
I am looking at implementing something roughly equivalent to strict
typing for a part of my code.
Has anybody else had a go at such a thing?

I have some data types which I'm implementing as classes (base types
like "int" but also more specific types like "country") and I'd like
to be able to use them as normal variables (as far as assigning and
retrieving it's value goes) with 'magic' happening inside the class
for validation and normalisation (eg accepting any ISO style country
code on assignment but standardising on alpha 2 on output).

I am aware of the capability to override the assignment operator for a
property of an object, ie use the __set() magic method so that
====
$object->var='hello';
====
is equivalent to:
====
$object->__set('var','hello');
====
allowing the __set() method to do some funky stuff.

Is there a similar capability to override the assignment operator on
the object itself, ie have:
====
$object='hello';
====
handled by a method on the $object?

Similarly the __toString() magic method would cover part of the
"getter" overriding, but it seems to be a special case override that
only works within specific string functions rather than a generic
getter override.

Paul

--- End Message ---
--- Begin Message ---
On 1 March 2011 04:40, Paul McGarry <p...@paulmcgarry.com> wrote:
> I am looking at implementing something roughly equivalent to strict
> typing for a part of my code.
> Has anybody else had a go at such a thing?
>
> I have some data types which I'm implementing as classes (base types
> like "int" but also more specific types like "country") and I'd like
> to be able to use them as normal variables (as far as assigning and
> retrieving it's value goes) with 'magic' happening inside the class
> for validation and normalisation (eg accepting any ISO style country
> code on assignment but standardising on alpha 2 on output).
>
> I am aware of the capability to override the assignment operator for a
> property of an object, ie use the __set() magic method so that
> ====
> $object->var='hello';
> ====
> is equivalent to:
> ====
> $object->__set('var','hello');
> ====
> allowing the __set() method to do some funky stuff.
>
> Is there a similar capability to override the assignment operator on
> the object itself, ie have:
> ====
> $object='hello';
> ====
> handled by a method on the $object?
>
> Similarly the __toString() magic method would cover part of the
> "getter" overriding, but it seems to be a special case override that
> only works within specific string functions rather than a generic
> getter override.
>
> Paul
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

There is __invoke, but that is for ...

$instance()


The problem is (hopefully) explained in ...

$instance = 'something that needs to be passed to instance and not
assigned to instance';

How do you differentiate between the two "assignments" (one to the
variable and one to be processed by the instance) ?

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On Mon, Feb 28, 2011 at 10:07 PM, Alexis <phplis...@antonakis.co.uk> wrote:
> Hi,
>
> I know not strictly a PHP question, but was just wondering if someone can
> tell me the regex format for something please.
>
> I need to replace
> ......
> with
> --------

A good text editor should have find ...... and replace with  --------
under the search menu.

> That is six periods replaced by eight hyphens.
>
> Many thanks
> Alexis
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.

--- End Message ---
--- Begin Message ---
On Tue, Mar 1, 2011 at 2:28 AM, David Hutto <smokefl...@gmail.com> wrote:
> On Mon, Feb 28, 2011 at 10:07 PM, Alexis <phplis...@antonakis.co.uk> wrote:
>> Hi,
>>
>> I know not strictly a PHP question, but was just wondering if someone can
>> tell me the regex format for something please.
>>
>> I need to replace
>> ......
>> with
>> --------
>
> A good text editor should have find ...... and replace with  --------

> under the search menu.

My bad, that was for editing,.
>
>> That is six periods replaced by eight hyphens.
>>
>> Many thanks
>> Alexis
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
> --
> According to theoretical physics, the division of spatial intervals as
> the universe evolves gives rise to the fact that in another timeline,
> your interdimensional counterpart received helpful advice from me...so
> be eternally pleased for them.
>



-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.

--- End Message ---
--- Begin Message ---
"David Hutto" <smokefl...@gmail.com> wrote:

>On Tue, Mar 1, 2011 at 2:28 AM, David Hutto <smokefl...@gmail.com>
>wrote:
>> On Mon, Feb 28, 2011 at 10:07 PM, Alexis <phplis...@antonakis.co.uk>
>wrote:
>>> Hi,
>>>
>>> I know not strictly a PHP question, but was just wondering if
>someone can
>>> tell me the regex format for something please.
>>>
>>> I need to replace
>>> ......
>>> with
>>> --------
>>
>> A good text editor should have find ...... and replace with  --------
>
>> under the search menu.
>
>My bad, that was for editing,.
>>
>>> That is six periods replaced by eight hyphens.
>>>
>>> Many thanks
>>> Alexis
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>>
>>
>> --
>> According to theoretical physics, the division of spatial intervals
>as
>> the universe evolves gives rise to the fact that in another timeline,
>> your interdimensional counterpart received helpful advice from
>me...so
>> be eternally pleased for them.
>>
>
>
>
>--
>According to theoretical physics, the division of spatial intervals as
>the universe evolves gives rise to the fact that in another timeline,
>your interdimensional counterpart received helpful advice from me...so
>be eternally pleased for them.
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

If it needs to be done programatically then str_replace() will be faster than 
any regex.


Thanks
Ash
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--- End Message ---
--- Begin Message ---
On 1 March 2011 03:07, Alexis <phplis...@antonakis.co.uk> wrote:
> Hi,
>
> I know not strictly a PHP question, but was just wondering if someone can
> tell me the regex format for something please.
>
> I need to replace
> ......
> with
> --------
> That is six periods replaced by eight hyphens.
>
> Many thanks
> Alexis
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

$text = preg_replace('/\.{6}/', '--------', $text)

but

$text = str_replace('......', '--------', $text);

is going to quicker.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---

Reply via email to