php-general Digest 28 Oct 2011 08:18:47 -0000 Issue 7541

Topics (messages 315456 through 315480):

Re: Exporting large data from mysql to html using php
        315456 by: Jim Giner
        315467 by: Jason Pruim
        315468 by: Jason Pruim

Question reading a file
        315457 by: Tedd Sperling
        315461 by: Ashley Sheridan
        315463 by: Daniel Brown
        315464 by: Tedd Sperling

Execute permission question
        315458 by: Tedd Sperling
        315459 by: Larry Martell
        315460 by: Ashley Sheridan
        315465 by: Tedd Sperling
        315466 by: Daniel Brown
        315469 by: Tedd Sperling
        315470 by: Tedd Sperling
        315471 by: Daniel Brown

OpenId Provider
        315462 by: Roy Kaldung
        315475 by: Negin Nickparsa

Help with redeclare error
        315472 by: Jack
        315473 by: Jason Pruim
        315474 by: Daniel Brown
        315476 by: UltraMega Admin
        315478 by: Ashley Sheridan

Re: array_unique by id multi-dimensional array
        315477 by: tamouse mailing lists
        315479 by: Tontonq Tontonq
        315480 by: sivaji j.g

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 ---
>
> Good luck, that's a LOT of reading.  I'd estimate that's about 3k+ pages 
> of
> reading. :)
>
>
>> >
>> >
>> > Regards,
>> > Tommy
>>
>>
>
****************
nice to see someone else is finally getting the point that I'm been making. 



--- End Message ---
--- Begin Message ---
Jason Pruim
li...@pruimphotography.com



On Oct 27, 2011, at 2:44 PM, Tommy Pham wrote:

> On Wed, Oct 26, 2011 at 5:47 PM, Jason Pruim <li...@pruimphotography.com> 
> wrote:
> 
> Jason Pruim
> li...@pruimphotography.com
> 
> The server that's running it is a home computer with a VPS installed... It's 
> not my dev environment :)
> 
> 
> Home computer used for a production environment?  Wow.. I'm speechless.

Ummm... No... Home computer for a dev environment... The final product will be 
moved to a better host. This is temporary... And actually isn't a bad idea... 
If you get it running good on a cheap home computer, why wouldn't it run 
*BETTER* on the high-end production server?

>  
> The information being searched is specifically phone numbers, and the bosses 
> want to provide the public away to browse them, hence the pagination... Once 
> I removed a COUNT from mysql it started working alot better... So I still 
> need to provide a better pagination system, but it's working.
> 
> 
> If just showing phone numbers only and no other information, what's the point 
> since there are already several other white and yellow pages on the net?  
> There's even a reverse number look-up too.  There's also a well known paid 
> service for getting a DB of contacts (name, address, phone numbers of persons 
> and businesses).  Just out of curiosity, what is it that your boss intend to 
> offer that would stand out for already existing services?  I doubt anyone 
> would be sane enough to sit there and just browse through phone numbers only. 
>  Even if it does show the owner's name of the registered number, I highly 
> doubt anyone sane would browse unless you provide some kind of filter/search.

I'm not expecting people to look at every single page... But I need away to 
allow curious people the ability to page through results if they want. 
>  
> Oh, and the 89 million is just for one state :) We are talking the 
> possibility of I believe 10 billion numbers to cover the US, not to mention 
> Canada which I believe uses the same numbering system as we do so that could 
> be another 10 billion...
> 
> >
> > As I've mentioned, something of this magnitude is better to leave it to the
> > DBA and work together with that DBA.  Either hire/contract one or become one
> > :)
> 
> I'm working on becoming one ontop of web designer and programmer :)
> 
> Good luck, that's a LOT of reading.  I'd estimate that's about 3k+ pages of 
> reading. :)

I've always been a fan of reading :) Just wish I had more time to do it! :)



--- End Message ---
--- Begin Message ---
Jason Pruim
li...@pruimphotography.com



On Oct 27, 2011, at 4:08 PM, Nathan Nobbe wrote:

> On Mon, Oct 24, 2011 at 6:50 PM, Jason Pruim <li...@pruimphotography.com> 
> wrote:
> Now that I've managed to list 3 separate programming languages and somewhat 
> tie it back into php here's the question...
> 
> I have about 89 million records in mysql... the initial load of the page 
> takes 2 to 3 minutes, I am using pagination, so I have LIMIT's on the SQL 
> query's... But they just aren't going fast enough...
> 
> What I would like to do, is pull the data out of MySQL and store it in the 
> HTML files, and then update the HTML files once a day/week/month... I can 
> figure most of it out... BUT... How do I automatically link to the individual 
> pages?
> 
> I have the site working when you pull it from MySQL... Just the load time 
> sucks... Any suggestions on where I can pull some more info from? :)
> 
> Thanks in advance!
> 
> dial in the db schema (think keys) and queries; then investigate a reverse 
> proxy like varnish to cache the generated html.
> 
> you'll be able to handle a couple thousand requests per second against the 
> proxy in no time.
> 
> might be worth pre-generating some of the pages if they are still really slow 
> after db optimization.

Would it make sense that COUNT()'ing 89 million records would kill the 
performance? Once that was gone... It worked perfectly! 



--- End Message ---
--- Begin Message ---
Hi gang:

I have a few questions -- this is my first one.

Please review this link:

http://webbytedd.com/cccc/perms/

This page simply reads the contents of a file of the user's choice and displays 
the file's data.

My first question is with regard to reading a file ( fread() ):

If the user picks the PDF file, the [1] First 20 bytes are: %PDF... 
If the user picks a JPG file, the [1] First 20 bytes are:  ...JFFIF... 
If the user picks a GIF file, the [1] First 20 bytes are:  GIF89a... 

Of course, the above is just reading/echoing the header for each of those files.

Likewise, if the user picks a TXT or CSS file, then [1] First 20 bytes echoed 
are the first 20 characters of the file.

However, if the user picks a HTML or PHP file, there are no [1] First 20 bytes 
echoed.

BUT, the ord() and chr() of the bytes ARE indeed collected and can be echoed as 
shown in statements [2] and [3].

So, my question is specifically "Why is the data gathered in the variable 
$content not echoed for the HTML and PHP files, but is for all other files?" 

Please review the code shown.

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com






--- End Message ---
--- Begin Message ---
On Thu, 2011-10-27 at 15:25 -0400, Tedd Sperling wrote:

> Hi gang:
> 
> I have a few questions -- this is my first one.
> 
> Please review this link:
> 
> http://webbytedd.com/cccc/perms/
> 
> This page simply reads the contents of a file of the user's choice and 
> displays the file's data.
> 
> My first question is with regard to reading a file ( fread() ):
> 
> If the user picks the PDF file, the [1] First 20 bytes are: %PDF... 
> If the user picks a JPG file, the [1] First 20 bytes are:  ...JFFIF... 
> If the user picks a GIF file, the [1] First 20 bytes are:  GIF89a... 
> 
> Of course, the above is just reading/echoing the header for each of those 
> files.
> 
> Likewise, if the user picks a TXT or CSS file, then [1] First 20 bytes echoed 
> are the first 20 characters of the file.
> 
> However, if the user picks a HTML or PHP file, there are no [1] First 20 
> bytes echoed.
> 
> BUT, the ord() and chr() of the bytes ARE indeed collected and can be echoed 
> as shown in statements [2] and [3].
> 
> So, my question is specifically "Why is the data gathered in the variable 
> $content not echoed for the HTML and PHP files, but is for all other files?" 
> 
> Please review the code shown.
> 
> Cheers,
> 
> tedd
> 
> _____________________
> t...@sperling.com
> http://sperling.com
> 
> 
> 
> 
> 
> 


This might sound silly, but is it because it's being interpreted
somehow? I could understand the HTML going a little weird because of
this, not sure about the PHP, would depend what was trying to interpret
it...
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Thu, Oct 27, 2011 at 15:25, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> Hi gang:
>
> I have a few questions -- this is my first one.
>
> Please review this link:
>
> http://webbytedd.com/cccc/perms/
>
> This page simply reads the contents of a file of the user's choice and 
> displays the file's data.
>
> My first question is with regard to reading a file ( fread() ):
>
> If the user picks the PDF file, the [1] First 20 bytes are: %PDF...
> If the user picks a JPG file, the [1] First 20 bytes are:  ...JFFIF...
> If the user picks a GIF file, the [1] First 20 bytes are:  GIF89a...
>
> Of course, the above is just reading/echoing the header for each of those 
> files.
>
> Likewise, if the user picks a TXT or CSS file, then [1] First 20 bytes echoed 
> are the first 20 characters of the file.
>
> However, if the user picks a HTML or PHP file, there are no [1] First 20 
> bytes echoed.
>
> BUT, the ord() and chr() of the bytes ARE indeed collected and can be echoed 
> as shown in statements [2] and [3].
>
> So, my question is specifically "Why is the data gathered in the variable 
> $content not echoed for the HTML and PHP files, but is for all other files?"
>
> Please review the code shown.

    No need to review the code.  The first hunch I had proved correct.
 PHP opens with a less-than (left carat, or 'less-than') symbol, as do
HTML tags.  As a result, the browser interprets both as tags and tries
to parse them.

    Viewing the source of that page upon selection of the PHP or HTML
options displays the code as expected.

    Resolution:  str_replace('<','&lt;',str_replace('>','&gt;',$data));

    Technically, only the less-than symbols need to be replaced, but
you may as well - as Charley Jordan says - Keep It Clean.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
On Oct 27, 2011, at 5:14 PM, Daniel Brown wrote:
> On Thu, Oct 27, 2011 at 15:25, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>> -snip my confusion -
> 
>    No need to review the code.  The first hunch I had proved correct.
> PHP opens with a less-than (left carat, or 'less-than') symbol, as do
> HTML tags.  As a result, the browser interprets both as tags and tries
> to parse them.
> 
> -snip-
> 
> -- 
> </Daniel P. Brown>

Daniel:

But of course. I never considered that the "<" in both the HTML (<!doctype 
html>) and the PHP (<?php) would cause the browser to wig-out and not display 
the contents of the file -- good catch!

I knew there was something wrong -- I just didn't realize that the Browser was 
trying to think for me. That'll teach me to use a Browser as a hex-viewer.

Thanks,

tedd

_____________________
t...@sperling.com
http://sperling.com





--- End Message ---
--- Begin Message ---
Hi gang:

Another question -- in the context of file permissions (rwx) is the execute 
permission limited to shell commands -- Or -- is there more?

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com






--- End Message ---
--- Begin Message ---
On Thu, Oct 27, 2011 at 2:26 PM, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> Hi gang:
>
> Another question -- in the context of file permissions (rwx) is the execute 
> permission limited to shell commands -- Or -- is there more?

Not sure I fully understand your question, but to execute anything
directly - shell script, python script, perl script, binary program -
you need the x bit set. I say directly because you could do: 'perl
script' without script being executable (because in that case it's an
argument to the perl executable).


HTH,
-larry

--- End Message ---
--- Begin Message ---
On Thu, 2011-10-27 at 14:41 -0600, Larry Martell wrote:

> On Thu, Oct 27, 2011 at 2:26 PM, Tedd Sperling <tedd.sperl...@gmail.com> 
> wrote:
> > Hi gang:
> >
> > Another question -- in the context of file permissions (rwx) is the execute 
> > permission limited to shell commands -- Or -- is there more?
> 
> Not sure I fully understand your question, but to execute anything
> directly - shell script, python script, perl script, binary program -
> you need the x bit set. I say directly because you could do: 'perl
> script' without script being executable (because in that case it's an
> argument to the perl executable).
> 
> 
> HTH,
> -larry
> 


Yes, I just ran a quick test PHP script without any execute permissions
set at all, only rw-rw-r-- and it ran just fine, suggesting it is just
an argument as Larry said.

I don't think Apache needs execute permissions set on PHP files or pages
either, only read rights.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Oct 27, 2011, at 4:51 PM, Ashley Sheridan wrote:
> Yes, I just ran a quick test PHP script without any execute permissions set 
> at all, only rw-rw-r-- and it ran just fine, suggesting it is just an 
> argument as Larry said.
> 
> I don't think Apache needs execute permissions set on PHP files or pages 
> either, only read rights.
> 
> -- 
> Thanks,
> Ash

Ash:

You answered a question I wasn't prepared to ask, which was "How can php 
scripts be executed when their execute permissions aren't set?"

That question begged the question of "What does execute mean?"

I find the topic of permissions complicated when they can be overridden 
elsewhere.

Thanks,

tedd

_____________________
t...@sperling.com
http://sperling.com






--- End Message ---
--- Begin Message ---
On Thu, Oct 27, 2011 at 18:15, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>
> Ash:
>
> You answered a question I wasn't prepared to ask, which was "How can php 
> scripts be executed when their execute permissions aren't set?"
>
> That question begged the question of "What does execute mean?"

    It means "execute."  Not to be confused with what others are
mentioning here, which is "read and interpret."  If you run something
through PHP, Perl, Python, or another parser/interpreter, it doesn't
need to be executable by the user, only readable.

    A caveat to this, of course, is that some scripts (such as those
run via CGI) will usually need to be executable.  You may recall, back
in the 90's, that any Perl scripts you'd upload to your cgi-bin needed
to be chmod'd to 0755.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
On Oct 27, 2011, at 6:27 PM, Daniel Brown wrote:

> On Thu, Oct 27, 2011 at 18:15, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>> 
>> Ash:
>> 
>> You answered a question I wasn't prepared to ask, which was "How can php 
>> scripts be executed when their execute permissions aren't set?"
>> 
>> That question begged the question of "What does execute mean?"
> 
>    It means "execute."  Not to be confused with what others are
> mentioning here, which is "read and interpret."  If you run something
> through PHP, Perl, Python, or another parser/interpreter, it doesn't
> need to be executable by the user, only readable.
> 
>    A caveat to this, of course, is that some scripts (such as those
> run via CGI) will usually need to be executable.  You may recall, back
> in the 90's, that any Perl scripts you'd upload to your cgi-bin needed
> to be chmod'd to 0755.
> 
> -- 
> </Daniel P. Brown>

Thanks for the wayback machine ride -- my memory cells have long expunged that 
data for more useless information.

Good point re comparison of "execute" vs "read and interpret" -- that will end 
up in the minds of students to ponder.

Thanks,

tedd

_____________________
t...@sperling.com
http://sperling.com





--- End Message ---
--- Begin Message ---
On Oct 27, 2011, at 6:27 PM, Daniel Brown wrote:
> On Thu, Oct 27, 2011 at 18:15, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>> That question begged the question of "What does execute mean?"
> 
>    It means "execute."  Not to be confused with what others are
> mentioning here, which is "read and interpret."  If you run something
> through PHP, Perl, Python, or another parser/interpreter, it doesn't
> need to be executable by the user, only readable.
> 
>    A caveat to this, of course, is that some scripts (such as those
> run via CGI) will usually need to be executable.  You may recall, back
> in the 90's, that any Perl scripts you'd upload to your cgi-bin needed
> to be chmod'd to 0755.
> 
> -- 
> </Daniel P. Brown>

One of the things I'm trying to understand is a php script can execute a shell 
command, right? Is there a way via permissions to prevent that -- or -- does 
that even have anything to do with it? That's where I'm fuzzy.

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com

--- End Message ---
--- Begin Message ---
On Thu, Oct 27, 2011 at 19:44, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
>
> One of the things I'm trying to understand is a php script can execute a 
> shell command, right? Is there a way via permissions to prevent that -- or -- 
> does that even have anything to do with it? That's where I'm fuzzy.

    Sure.  What PHP actually does is interface with a forked shell
(usually 'sh' by default) process, and the shell then has permission
controls and requirements of its own, defined by the operating
system's configuration.  So PHP isn't actually executing the commands,
per se, but is instead instructing the shell to do so itself.  To see
how to limit PHP's shell access, look into safe_mode and the like.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
Hi,

Can anybody recommend a good OpenId Provider?
I need one with LDAP integration if available.

tia,
Roy

-- 
Roy Kaldung



--- End Message ---
--- Begin Message ---
I don't know about LDAP but Zend openID provider can be a good choice
http://framework.zend.com/manual/en/zend.openid.html

On 10/28/11, Roy Kaldung <r...@kaldung.com> wrote:
> Hi,
>
> Can anybody recommend a good OpenId Provider?
> I need one with LDAP integration if available.
>
> tia,
> Roy
>
> --
> Roy Kaldung
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hello All,

 

I have some code that just broke with a PHP upgrade, the error says:

PHP Fatal error:  Cannot redeclare date_diff() the line of the error is the
close bracket of the function which is below.

Any ideas what's going on, I'm stuck?

 

 

 

function date_diff($start_time, $stop_time) {

 $seconds   = strtotime($stop_time)-strtotime($start_time);

$days      = intval($seconds/86400);

$seconds  -= $days*86400;

$hours     = sprintf("%02d",intval($seconds/3600));

$seconds  -= $hours*3600;       

 $minutes   = sprintf("%02d",intval($seconds/60));

$seconds  -= sprintf("%02d",$minutes*60);               

 

# $time_diff = "Days=>" . $days . "  Hours=>" . $hours . "  Minutes=>" .
$minutes . "  Seconds=>" . $seconds;

$time_diff = $hours . ":" . $minutes;

 return($time_diff);             

}                                

 

 

Everywhere I call the function it looks like this:

date_diff($fldstart_time,$fldstop_time);

 

 

 

 

Thanks!

Jack

 


--- End Message ---
--- Begin Message ---
Jason Pruim
li...@pruimphotography.com



On Oct 27, 2011, at 7:55 PM, Jack wrote:

> Hello All,
> 
> 
> 
> I have some code that just broke with a PHP upgrade, the error says:
> 
> PHP Fatal error:  Cannot redeclare date_diff() the line of the error is the
> close bracket of the function which is below.
> 
> Any ideas what's going on, I'm stuck?

Most likely you have in included in 2 files... Look into it from that angle... 
It only needs to be included in 1 file to work throughout all the files.



--- End Message ---
--- Begin Message ---
On Thu, Oct 27, 2011 at 20:06, Jason Pruim <li...@pruimphotography.com> wrote:
>
> Most likely you have in included in 2 files... Look into it from that 
> angle... It only needs to be included in 1 file to work throughout all the 
> files.

    Prune is spot-on.  That error generally happens when you include a
file that has already been included, which contains function
definitions.  Look at the code in the files the error mentions, on the
lines it specifies, and - most likely - you'll see an include.
Changing them to include_once instead will resolve the issue, as PHP
will just skip the order if it's already been done within the
execution of the code.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
On 10/27/2011 5:33 PM, Daniel Brown wrote:
On Thu, Oct 27, 2011 at 20:06, Jason Pruim<li...@pruimphotography.com>  wrote:
Most likely you have in included in 2 files... Look into it from that angle... 
It only needs to be included in 1 file to work throughout all the files.
     Prune is spot-on.  That error generally happens when you include a
file that has already been included, which contains function
definitions.  Look at the code in the files the error mentions, on the
lines it specifies, and - most likely - you'll see an include.
Changing them to include_once instead will resolve the issue, as PHP
will just skip the order if it's already been done within the
execution of the code.


A function with that name already exists in PHP as of 5.3.0. You'll have to rename it or something.

http://us2.php.net/manual/en/function.date-diff.php

--- End Message ---
--- Begin Message ---
On Thu, 2011-10-27 at 17:40 -0700, UltraMega Admin wrote:

> On 10/27/2011 5:33 PM, Daniel Brown wrote:
> > On Thu, Oct 27, 2011 at 20:06, Jason Pruim<li...@pruimphotography.com>  
> > wrote:
> >> Most likely you have in included in 2 files... Look into it from that 
> >> angle... It only needs to be included in 1 file to work throughout all the 
> >> files.
> >      Prune is spot-on.  That error generally happens when you include a
> > file that has already been included, which contains function
> > definitions.  Look at the code in the files the error mentions, on the
> > lines it specifies, and - most likely - you'll see an include.
> > Changing them to include_once instead will resolve the issue, as PHP
> > will just skip the order if it's already been done within the
> > execution of the code.
> >
> 
> A function with that name already exists in PHP as of 5.3.0. You'll have 
> to rename it or something.
> 
> http://us2.php.net/manual/en/function.date-diff.php
> 



Or wrap it inside a function_exists() call assuming that both your
function and the internal one do the same thing.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Thu, Oct 27, 2011 at 10:31 AM, Tontonq Tontonq <root...@gmail.com> wrote:
> i have an array like
>
>  [0] => Array
> (
> [likes] => 113091
>  [name] => blabla
>  [access_token] => AAABZCTx
> [id] => 188206217874932
>
> )
>
>  [1] => Array
> (
> [likes] => 113091
> [name] => blabla
> [access_token] =>   AAABZCTz
> [id] => 188206217874932
>   )
>
> i want to filter the array by [id] sub value?
>

Not quite sure what you mean by "filter" in this case, but the
function that pops to mind is
http://www.php.net/manual/en/function.array-filter.php, which applies
a callback function to each member of the array where you can
determine if it should be included in the filtered list by returning
true.

--- End Message ---
--- Begin Message ---
let me explain again
this is my array
Array
(
[0] => Array
(
[likes] => 137846
[name] => blabla
[access_token] => AAABZBD
[id] => 157644197612598
[link] => http://www.facebook.com/blabla
)

[1] => Array
(
[likes] => 137698
[name] => blabla
[access_token] => AAAnnL
[id] => 157644197612598
[link] => http://www.facebook.com/blabla
)

[2] => Array
(
[likes] => 134391
[name] => sieaq
[access_token] => AAA04
[id] => 163744743683729
[link] => http://www.facebook.com/zart
)


[3] => Array
(
[name] => defolaq
[access_token] => AAAZD
[id] => 139820007610
[link] => http://www.facebook.com/apps/application.php?id=239820007640
[likes] => 0
)

[4] => Array
(
[name] => falan
[access_token] => AAW4NNGAZDZD
[id] => 374971333999
[link] => http://www.facebook.com/apps/application.php?id=374951333399
[likes] => 0
)

[5] => Array
(
[name] => filan
[access_token] => AAABZCTCw
[id] => 237184173662497
[link] => http://www.facebook.com/pages/filan/237184173662497
[likes] => 0
)

[6] => Array
(
[name] => bigit
[access_token] => Jj77twGFvS8YyB
[id] => 10497735291210
[link] => http://www.facebook.com/pages/bigit/10497735291210
[likes] => 0
)
)

but as you see there are 2 sub array with [id] =>  157644197612598
i want to delete sub arrays repeated with same id.?

2011/10/28 tamouse mailing lists <tamouse.li...@gmail.com>

> On Thu, Oct 27, 2011 at 10:31 AM, Tontonq Tontonq <root...@gmail.com>
> wrote:
> > i have an array like
> >
> >  [0] => Array
> > (
> > [likes] => 113091
> >  [name] => blabla
> >  [access_token] => AAABZCTx
> > [id] => 188206217874932
> >
> > )
> >
> >  [1] => Array
> > (
> > [likes] => 113091
> > [name] => blabla
> > [access_token] =>   AAABZCTz
> > [id] => 188206217874932
> >   )
> >
> > i want to filter the array by [id] sub value?
> >
>
> Not quite sure what you mean by "filter" in this case, but the
> function that pops to mind is
> http://www.php.net/manual/en/function.array-filter.php, which applies
> a callback function to each member of the array where you can
> determine if it should be included in the filtered list by returning
> true.
>

--- End Message ---
--- Begin Message ---
On Fri, Oct 28, 2011 at 1:22 PM, Tontonq Tontonq <root...@gmail.com> wrote:

> let me explain again
> this is my array
> Array
> (
> [0] => Array
> (
> [likes] => 137846
> [name] => blabla
> [access_token] => AAABZBD
> [id] => 157644197612598
> [link] => http://www.facebook.com/blabla
> )
>
> [1] => Array
> (
> [likes] => 137698
> [name] => blabla
> [access_token] => AAAnnL
> [id] => 157644197612598
> [link] => http://www.facebook.com/blabla
> )
>
> [2] => Array
> (
> [likes] => 134391
> [name] => sieaq
> [access_token] => AAA04
> [id] => 163744743683729
> [link] => http://www.facebook.com/zart
> )
>
>
> [3] => Array
> (
> [name] => defolaq
> [access_token] => AAAZD
> [id] => 139820007610
> [link] => http://www.facebook.com/apps/application.php?id=239820007640
> [likes] => 0
> )
>
> [4] => Array
> (
> [name] => falan
> [access_token] => AAW4NNGAZDZD
> [id] => 374971333999
> [link] => http://www.facebook.com/apps/application.php?id=374951333399
> [likes] => 0
> )
>
> [5] => Array
> (
> [name] => filan
> [access_token] => AAABZCTCw
> [id] => 237184173662497
> [link] => http://www.facebook.com/pages/filan/237184173662497
> [likes] => 0
> )
>
> [6] => Array
> (
> [name] => bigit
> [access_token] => Jj77twGFvS8YyB
> [id] => 10497735291210
> [link] => http://www.facebook.com/pages/bigit/10497735291210
> [likes] => 0
> )
> )
>
> but as you see there are 2 sub array with [id] =>  157644197612598
> i want to delete sub arrays repeated with same id.?
>

If my understanding is right, a simple foreach loop and unset() will do
this. Below is the untested version of snippet I would use to remove the
duplicate sub arrays,

$id = array();
foreach ($items as $key => $item) {
  if (in_array($item['id'], $id)) {
    unset($items[$key]);
  }
  else {
    $id[] = $item['id'];
  }
}


-- 
Sivaji
http://sivaji.drupalgardens.com
@sivaji_ganesh <https://twitter.com/#%21/sivaji_ganesh> in twitter
sivaji2...@gmail.com
Gtalk / Skype: sivaji2009


>
>

--- End Message ---

Reply via email to