Sunday, 15 September 2013

php - How to display an array $key with this pattern promote-1 for which 1 can be any whole number? -



php - How to display an array $key with this pattern promote-1 for which 1 can be any whole number? -

function name( $key, $value ) { switch( $key ) { case 'name': break; // determine key pattern 1-100 case 'promote-'.count++ : break; } }

when echo $key sample outputs contact_number, card_name , pattern determine promote-1, promote-2 , on. sec alternative "case 'promote-'.count++" pattern need determine. 'promote-1' 'promote-100' fall on option

use of switch case restricted. here working solution you.

function name( $key, $value ) { if(strpos($key,'-') > 0){ $key_arry = explode('-' , $key); if($key_arry[0] == 'promote' && ($key_arry[1] > 0 || $key_arry[1] <= 100)){ echo 'patern promote-1, promote-2......promote-100'; }else{ echo 'anything else'; } } } name('promote-2' , 1);

php

No comments:

Post a Comment