php-general Digest 28 Feb 2012 16:36:34 -0000 Issue 7705

Topics (messages 316783 through 316788):

Re: Insert new array after specific key in multidimensional array
        316783 by: Eray Alakese
        316785 by: Micky Hulse
        316786 by: xucheng
        316787 by: Micky Hulse
        316788 by: Shawn McKenzie

Re: MySQL over TCP results on CLOSE_WAIT state in PHP 5.3.8
        316784 by: Tommy Pham

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 ---
$newarray = array() ;
foreach($o as $key => $val)
{
     if($prevkey != 'specifickey') {
     $prevkey = $key;
     $newarray[$key] = $val;
     }
     else
     $newarray[] = $o_insert;
}

i think this would help you.  i can't test it,  I'm sending this from
mobile phone :-)

Eray Alakese
28 Şub 2012 04:13 tarihinde "Micky Hulse" <mickyhulse.li...@gmail.com>
yazdı:

> Howdy!
>
> Example code:
>
> <https://gist.github.com/1928452>
>
> What would be the best way to insert $o_insert array into $o array
> after specified key?
>
> I hate to just ask for example code, but I can't seem to find the
> perfect solution. :(
>
> Many thanks in advance for the help!
>
> Cheers,
> Micky
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Thank you Eray! That's a cool approach. Testing code now. I will be
back with my results. :)

Thank you!!!

Cheers,
M

--- End Message ---
--- Begin Message ---
Maybe you can trans the array into a xml tree , then modify its leaves .

RTFSC - Read The F**king Source Code :)!


2012/2/28 Micky Hulse <mickyhulse.li...@gmail.com>

> Thank you Eray! That's a cool approach. Testing code now. I will be
> back with my results. :)
>
> Thank you!!!
>
> Cheers,
> M
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

On Mon, Feb 27, 2012 at 7:41 PM, xucheng <helloworldje...@gmail.com> wrote:
> Maybe you can trans the array into a xml tree , then modify its leaves .

Now that sounds like an interesting idea... I will have to research
that as an option. Thanks for tip! :)

@Eray,

I was not able to get your code to work on my array... After working
with it a little bit, I realized your idea was very similar to these
others that I have found (great minds think alike):

http://eosrei.net/articles/2011/11/php-arrayinsertafter-arrayinsertbefore
http://drupal.org/node/66183

Your suggestion, and the ones above, work great if I "break out" the
key, pass it directly, then add the key back to the original array.

I have updated my gist and also put the code here:

<http://codepad.org/IY0y9Oy6>

Could things be optimized, or is this an acceptable solution?

Thanks!

Cheers,
Micky

--- End Message ---
--- Begin Message ---
On 02/27/2012 08:12 PM, Micky Hulse wrote:
> Howdy!
> 
> Example code:
> 
> <https://gist.github.com/1928452>
> 
> What would be the best way to insert $o_insert array into $o array
> after specified key?
> 
> I hate to just ask for example code, but I can't seem to find the
> perfect solution. :(
> 
> Many thanks in advance for the help!
> 
> Cheers,
> Micky


Might be an easier way but this should work.  You can sort the $before =
true out for yourself :-)

function array_insert(&$array, $key, $insert, $before = FALSE) {
    $i = 0;
    foreach($array as $k => $v) {
      if($k === $key) {
        $p = $i + 1;
        break;
      }
      $i++;
    }
    $array = array_merge(array_slice($array, 0, $p), $insert,
array_slice($array, $p, count($array) - $p));
}

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On Mon, Feb 27, 2012 at 4:06 AM,  <php-l...@dubistmeinheld.de> wrote:
> Hi,
>
> I have a MySQL server A, a server B with PHP 5.3.8 and a server C with PHP
> 5.3.3. I'm connecting to the MySQL server on A via TCP from B and C using an
> internal network. Server B and C use the same PHP application. There are also
> same PHP scripts that get data from the database and then calculate up to 30
> minutes. I close all database connection before doing the calculation to save
> connections (and ports) using:
> $thread_id = mysqli_thread_id( $this->handle );
> mysqli_kill(  $this->handle, $thread_id );
> mysqli_close( $this->handle );
>
> During a review on our servers I discovered that server B has a lot of network
> connection in the state "CLOSE_WAIT". Server C running the same PHP
> application has not. I see the difference that server B is using mysqlnd and
> server C not.
>
> serverB# netstat -an | grep 3306
> tcp        1      0 10.8.0.58:47455         10.8.0.1:3306           CLOSE_WAIT
>
> serverA# cat firewall
> Feb 17 16:21:49 www kernel: [6587053.325075] SFW2-OUT-ERROR IN= OUT=tun0
> SRC=10.8.0.1 DST=10.8.0.58 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP
> SPT=3306 DPT=47455 WINDOW=0 RES=0x00 RST URGP=0
>
> Does anybody have an idea why this happens? How can I avoid this or
> investigate in this? Is this a know issue?
>

Is the underlying OS for servers B & C exactly the same? Down to
kernel version (if Linux/Unix), NICs and driver version,
configurations, etc.?  It would help if specify OS type and kernel
version.

Best regards,
Tommy

--- End Message ---

Reply via email to