identify a value in the key of an array

Asked

Viewed 33 times

-2

The return of values stored on array $_POST is this:

array(373) {
  ["ativar1"]=>
  string(17) "Ativar Permissões"
  ["copiar1"]=>
  string(0) ""
  ["p0"]=>
  string(1) "M"
  ["p1"]=>
  string(1) "N"
  ["p5"]=>
  string(1) "S"
  ["descontop"]=>
  string(4) "5.00"
  ["descontod"]=>
  string(4) "0.99"
  ["p6"]=>
  string(1) "S"
  ["p7"]=>
  string(1) "S"
  ["p8"]=>
  string(1) "S"
  ["p26"]=>
  string(1) "S"
  ["p10"]=>
  string(1) "S"
  ["p11"]=>
  string(1) "S"
  ["p12"]=>
  string(1) "S"
  ["p13"]=>
  string(1) "3"
  ["p14"]=>
  string(1) "S"
  ["p15"]=>
  string(1) "E"
  ["p16"]=>
  string(1) "N"
  ["p17"]=>
  string(1) "S"
  ["p18"]=>
  string(1) "S"
  ["p19"]=>
  string(1) "S"
  ["p20"]=>
  string(1) "S"
  ["p21"]=>
  string(1) "S"
  ["p22"]=>
  string(1) "S"
  ["p2"]=>
  string(1) "S"
  ["p23"]=>
  string(1) "S"
  ["p24"]=>
  string(1) "S"
  ["p3"]=>
  string(1) "S"
  ["p4"]=>
  string(1) "S"
  ["p9"]=>
  string(1) "2"
  ["p25"]=>
  string(1) "S"
  ["p27"]=>
  string(1) "N"
  ["p29"]=>
  string(1) "N"
  ["p30"]=>
  string(1) "N"
  ["p33"]=>
  string(1) "S"
  ["p28"]=>
  string(1) "5"
  ["compra"]=>
  string(5) "10.00"
  ["p31"]=>
  string(1) "S"
  ["p32"]=>
  string(1) "S"
  ["p42"]=>
  string(1) "L"
  ["p34"]=>
  string(1) "S"
  ["p35"]=>
  string(1) "X"
  ["p36"]=>
  string(1) "S"
  ["p37"]=>
  string(1) "S"
  ["p38"]=>
  string(1) "S"
  ["nfesaida0"]=>
  string(1) "1"
  ["nfesaida1"]=>
  string(1) "1"
  ["nfesaida2"]=>
  string(1) "1"
  ["nfesaida3"]=>
  string(1) "1"
  ["nfesaida4"]=>
  string(1) "1"
  ["nfesaida5"]=>
  string(1) "1"
  ["nfesaida6"]=>
  string(1) "1"
  ["nfesaida7"]=>
  string(1) "1"
  ["nfesaida8"]=>
  string(1) "1"
  ["nfesaida9"]=>
  string(1) "1"
  ["nfesaida11"]=>
  string(1) "1"
  ["p40"]=>
  string(1) "S"
  ["p39"]=>
  string(1) "S"
  ["p41"]=>
  string(1) "S"
  ["p44"]=>
  string(1) "S"
  ["p45"]=>
  string(1) "N"
  ["p46"]=>
  string(1) "S"
  ["p47"]=>
  string(1) "S"
  ["p48"]=>
  string(1) "S"
  ["p49"]=>
  string(1) "N"
  ["p50"]=>
  string(1) "1"
  ["p51"]=>
  string(1) "1"
  ["p52"]=>
  string(1) "1"
  ["p53"]=>
  string(1) "1"
  ["p54"]=>
  string(1) "1"
  ["p58"]=>
  string(1) "N"
  ["p56"]=>
  string(1) "S"
  ["p57"]=>
  string(1) "N"
  ["p60"]=>
  string(1) "S"
  ["p59"]=>
  string(1) "M"
  ["p61"]=>
  string(1) "N"
  ["p62"]=>
  string(1) "N"
  ["p63"]=>
  string(1) "N"
  ["p64"]=>
  string(1) "N"
  ["p65"]=>
  string(1) "L"
  ["p66"]=>
  string(1) "N"
  ["p67"]=>
  string(1) "N"
  ["copiar2"]=>
  string(0) ""
  ["m1"]=>
  string(1) "S"
  ["m2"]=>
  string(1) "S"
  ["m43"]=>
  string(1) "S"
  ["m197"]=>
  string(1) "S"
  ["m4"]=>
  string(1) "S"
  ["m5"]=>
  string(1) "S"
  ["m6"]=>
  string(1) "S"
  ["m7"]=>
  string(1) "S"
  ["m12"]=>
  string(1) "S"
  ["m13"]=>
  string(1) "S"
  ["m14"]=>
  string(1) "S"
  ["m29"]=>
  string(1) "S"
  ["m30"]=>
  string(1) "S"
  ["m31"]=>
  string(1) "S"
  ["m8"]=>
  string(1) "S"
  ["m15"]=>
  string(1) "S"
  ["m16"]=>
  string(1) "S"
  ["m18"]=>
  string(1) "S"
  ["m17"]=>
  string(1) "S"
  ["m9"]=>
  string(1) "S"
  ["m10"]=>
  string(1) "S"
  ["m11"]=>
  string(1) "S"
  ["m342"]=>
  string(1) "S"
  ["m343"]=>
  string(1) "S"
  ["m344"]=>
  string(1) "S"
  ["m345"]=>
  string(1) "S"
  ["m346"]=>
  string(1) "S"
  ["m347"]=>
  string(1) "S"
  ["m348"]=>
  string(1) "S"
  ["m349"]=>
  string(1) "S"
  ["m350"]=>
  string(1) "S"
  ["m351"]=>
  string(1) "S"
  ["m352"]=>
  string(1) "S"
  ["m353"]=>
  string(1) "S"
  ["m356"]=>
  string(1) "S"
  ["m357"]=>
  string(1) "S"
  ["m358"]=>
  string(1) "S"
  ["m373"]=>
  string(1) "S"
  ["m384"]=>
  string(1) "S"
  ["m360"]=>
  string(1) "S"
  ["m361"]=>
  string(1) "S"
  ["m368"]=>
  string(1) "S"
  ["m362"]=>
  string(1) "S"
  ["m363"]=>
  string(1) "S"
  ["m367"]=>
  string(1) "S"
  ["m379"]=>
  string(1) "S"
  ["m364"]=>
  string(1) "S"
  ["m365"]=>
  string(1) "S"
  ["m366"]=>
  string(1) "S"
  ["m374"]=>
  string(1) "S"
  ["m375"]=>
  string(1) "S"
  ["m380"]=>
  string(1) "S"
  ["m381"]=>
  string(1) "S"
  ["m382"]=>
  string(1) "S"
  ["m19"]=>
  string(1) "S"
  ["m20"]=>
  string(1) "S"
  ["m23"]=>
  string(1) "S"
  ["m24"]=>
  string(1) "S"
  ["m21"]=>
  string(1) "S"
  ["m22"]=>
  string(1) "S"
  ["m258"]=>
  string(1) "S"
  ["m138"]=>
  string(1) "S"
  ["m267"]=>
  string(1) "S"
  ["m53"]=>
  string(1) "S"
  ["m159"]=>
  string(1) "S"
  ["m262"]=>
  string(1) "S"
  ["m160"]=>
  string(1) "S"
  ["m263"]=>
  string(1) "S"
  ["m161"]=>
  string(1) "S"
  ["m163"]=>
  string(1) "S"
  ["m44"]=>
  string(1) "S"
  ["m268"]=>
  string(1) "S"
  ["m271"]=>
  string(1) "S"
  ["m272"]=>
  string(1) "S"
  ["m269"]=>
  string(1) "S"
  ["m254"]=>
  string(1) "S"
  ["m270"]=>
  string(1) "S"
  ["m88"]=>
  string(1) "S"
  ["m101"]=>
  string(1) "S"
  ["m102"]=>
  string(1) "S"
  ["m103"]=>
  string(1) "S"
  ["m104"]=>
  string(1) "S"
  ["m280"]=>
  string(1) "S"
  ["m106"]=>
  string(1) "S"
  ["m107"]=>
  string(1) "S"
  ["m231"]=>
  string(1) "S"
  ["m109"]=>
  string(1) "S"
  ["m111"]=>
  string(1) "S"
  ["m112"]=>
  string(1) "S"
  ["m110"]=>
  string(1) "S"
  ["m230"]=>
  string(1) "S"
  ["m232"]=>
  string(1) "S"
  ["m296"]=>
  string(1) "S"
  ["m297"]=>
  string(1) "S"
  ["m298"]=>
  string(1) "S"
  ["m299"]=>
  string(1) "S"
  ["m227"]=>
  string(1) "S"
  ["m228"]=>
  string(1) "S"
  ["m252"]=>
  string(1) "S"
  ["m45"]=>
  string(1) "S"
  ["m225"]=>
  string(1) "S"
  ["m250"]=>
  string(1) "S"
  ["m46"]=>
  string(1) "S"
  ["m60"]=>
  string(1) "S"
  ["m172"]=>
  string(1) "S"
  ["m248"]=>
  string(1) "S"
  ["m224"]=>
  string(1) "S"
  ["m183"]=>
  string(1) "S"
  ["m178"]=>
  string(1) "S"
  ["m253"]=>
  string(1) "S"
  ["m282"]=>
  string(1) "S"
  ["m184"]=>
  string(1) "S"
  ["m174"]=>
  string(1) "S"
  ["m182"]=>
  string(1) "S"
  ["m243"]=>
  string(1) "S"
  ["m173"]=>
  string(1) "S"
  ["m189"]=>
  string(1) "S"
  ["m187"]=>
  string(1) "S"
  ["m188"]=>
  string(1) "S"
  ["m181"]=>
  string(1) "S"
  ["m50"]=>
  string(1) "S"
  ["m202"]=>
  string(1) "S"
  ["m203"]=>
  string(1) "S"
  ["m287"]=>
  string(1) "S"
  ["m209"]=>
  string(1) "S"
  ["m339"]=>
  string(1) "S"
  ["m340"]=>
  string(1) "S"
  ["m359"]=>
  string(1) "S"
  ["m235"]=>
  string(1) "S"
  ["m241"]=>
  string(1) "S"
  ["m238"]=>
  string(1) "S"
  ["m286"]=>
  string(1) "S"
  ["m63"]=>
  string(1) "S"
  ["m190"]=>
  string(1) "S"
  ["m210"]=>
  string(1) "S"
  ["m204"]=>
  string(1) "S"
  ["m205"]=>
  string(1) "S"
  ["m200"]=>
  string(1) "S"
  ["m201"]=>
  string(1) "S"
  ["m206"]=>
  string(1) "S"
  ["m208"]=>
  string(1) "S"
  ["m222"]=>
  string(1) "S"
  ["m264"]=>
  string(1) "S"
  ["m198"]=>
  string(1) "S"
  ["m217"]=>
  string(1) "S"
  ["m218"]=>
  string(1) "S"
  ["m219"]=>
  string(1) "S"
  ["m338"]=>
  string(1) "S"
  ["m306"]=>
  string(1) "S"
  ["m52"]=>
  string(1) "S"
  ["m57"]=>
  string(1) "S"
  ["m58"]=>
  string(1) "S"
  ["m216"]=>
  string(1) "S"
  ["m25"]=>
  string(1) "S"
  ["m376"]=>
  string(1) "S"
  ["m377"]=>
  string(1) "S"
  ["m393"]=>
  string(1) "S"
  ["m378"]=>
  string(1) "S"
  ["m26"]=>
  string(1) "S"
  ["m27"]=>
  string(1) "S"
  ["m118"]=>
  string(1) "S"
  ["m56"]=>
  string(1) "S"
  ["m99"]=>
  string(1) "S"
  ["m266"]=>
  string(1) "S"
  ["m261"]=>
  string(1) "S"
  ["m90"]=>
  string(1) "S"
  ["m170"]=>
  string(1) "S"
  ["m207"]=>
  string(1) "S"
  ["m36"]=>
  string(1) "S"
  ["m260"]=>
  string(1) "S"
  ["m32"]=>
  string(1) "S"
  ["m136"]=>
  string(1) "S"
  ["m223"]=>
  string(1) "S"
  ["m251"]=>
  string(1) "S"
  ["m244"]=>
  string(1) "S"
  ["m59"]=>
  string(1) "S"
  ["m276"]=>
  string(1) "S"
  ["m293"]=>
  string(1) "S"
  ["m259"]=>
  string(1) "S"
  ["m34"]=>
  string(1) "S"
  ["m28"]=>
  string(1) "S"
  ["m35"]=>
  string(1) "S"
  ["m194"]=>
  string(1) "S"
  ["m236"]=>
  string(1) "S"
  ["m137"]=>
  string(1) "S"
  ["m199"]=>
  string(1) "S"
  ["m279"]=>
  string(1) "S"
  ["m237"]=>
  string(1) "S"
  ["m277"]=>
  string(1) "S"
  ["m278"]=>
  string(1) "S"
  ["m294"]=>
  string(1) "S"
  ["m402"]=>
  string(1) "S"
  ["m403"]=>
  string(1) "S"
  ["m404"]=>
  string(1) "S"
  ["m405"]=>
  string(1) "S"
  ["m55"]=>
  string(1) "S"
  ["m193"]=>
  string(1) "S"
  ["m169"]=>
  string(1) "S"
  ["m78"]=>
  string(1) "S"
  ["m81"]=>
  string(1) "S"
  ["m144"]=>
  string(1) "S"
  ["m83"]=>
  string(1) "S"
  ["m80"]=>
  string(1) "S"
  ["m79"]=>
  string(1) "S"
  ["m113"]=>
  string(1) "S"
  ["m283"]=>
  string(1) "S"
  ["m156"]=>
  string(1) "S"
  ["m265"]=>
  string(1) "S"
  ["m157"]=>
  string(1) "S"
  ["m162"]=>
  string(1) "S"
  ["m167"]=>
  string(1) "S"
  ["m158"]=>
  string(1) "S"
  ["m77"]=>
  string(1) "S"
  ["m281"]=>
  string(1) "S"
  ["m117"]=>
  string(1) "S"
  ["m155"]=>
  string(1) "S"
  ["m154"]=>
  string(1) "S"
  ["m120"]=>
  string(1) "S"
  ["m191"]=>
  string(1) "S"
  ["m142"]=>
  string(1) "S"
  ["m284"]=>
  string(1) "S"
  ["m114"]=>
  string(1) "S"
  ["m108"]=>
  string(1) "S"
  ["m255"]=>
  string(1) "S"
  ["m233"]=>
  string(1) "S"
  ["m273"]=>
  string(1) "S"
  ["m256"]=>
  string(1) "S"
  ["m229"]=>
  string(1) "S"
  ["m234"]=>
  string(1) "S"
  ["m257"]=>
  string(1) "S"
  ["m211"]=>
  string(1) "S"
  ["m213"]=>
  string(1) "S"
  ["m214"]=>
  string(1) "S"
  ["m335"]=>
  string(1) "S"
  ["m302"]=>
  string(1) "S"
  ["m247"]=>
  string(1) "S"
  ["m311"]=>
  string(1) "S"
  ["m226"]=>
  string(1) "S"
  ["m240"]=>
  string(1) "S"
  ["m220"]=>
  string(1) "S"
  ["m221"]=>
  string(1) "S"
  ["m289"]=>
  string(1) "S"
  ["m212"]=>
  string(1) "S"
  ["m68"]=>
  string(1) "S"
  ["m115"]=>
  string(1) "S"
  ["m303"]=>
  string(1) "S"
  ["m69"]=>
  string(1) "S"
  ["m75"]=>
  string(1) "S"
  ["m164"]=>
  string(1) "S"
  ["m70"]=>
  string(1) "S"
  ["m71"]=>
  string(1) "S"
  ["m73"]=>
  string(1) "S"
  ["m76"]=>
  string(1) "S"
  ["m396"]=>
  string(1) "S"
  ["m196"]=>
  string(1) "S"
  ["m215"]=>
  string(1) "S"
  ["m72"]=>
  string(1) "S"
  ["m242"]=>
  string(1) "S"
  ["m148"]=>
  string(1) "S"
  ["m119"]=>
  string(1) "S"
  ["m116"]=>
  string(1) "S"
  ["m153"]=>
  string(1) "S"
  ["m140"]=>
  string(1) "S"
  ["m143"]=>
  string(1) "S"
  ["m192"]=>
  string(1) "S"
  ["m195"]=>
  string(1) "S"
  ["m139"]=>
  string(1) "S"
  ["m285"]=>
  string(1) "S"
  ["m67"]=>
  string(1) "S"
  ["m288"]=>
  string(1) "S"
  ["m54"]=>
  string(1) "S"
  ["m249"]=>
  string(1) "S"
  ["m64"]=>
  string(1) "S"
  ["m89"]=>
  string(1) "S"
  ["m91"]=>
  string(1) "S"
  ["m92"]=>
  string(1) "S"
  ["m141"]=>
  string(1) "S"
  ["m100"]=>
  string(1) "S"
  ["m93"]=>
  string(1) "S"
  ["m152"]=>
  string(1) "S"
  ["m149"]=>
  string(1) "S"
  ["m150"]=>
  string(1) "S"
  ["m300"]=>
  string(1) "S"
  ["m151"]=>
  string(1) "S"
  ["m275"]=>
  string(1) "S"
  ["m245"]=>
  string(1) "S"
  ["m246"]=>
  string(1) "S"
  ["qual"]=>
  string(2) "38"
  ["p55"]=>
  string(1) "0"
  ["p43"]=>
  string(1) "L"
}

What I need is the following, (and I have absolutely no idea how to get it): notice that it has content that starts with $_POST['p0'], $_POST['p1'], ..., $_POST['p67']. Where the value 67 is the highest among those listed. How I can get the value 67 of this key?

Thanks in advance.

2 answers

0


If it’s useful to someone. I don’t know if it’s the smartest way, but I did so.

   #verificando quantas post 'p' tem
   foreach($_POST as $k => $v) $perm[trim(substr($k, 1, 4))] = $v;          

   //ordenando as chaves
   ksort($perm); 

   //monto string que eu preciso
   foreach($perm as $pp => $val) $p .= $val;

0

One way would be to use the foreach to identify the key and use a preg_match to pull the numbers:

foreach ($_POST as $key => $value) {
   preg_match_all('!\d+!', $key, $numero);
   print_r($numero);
}
  • Thanks for the reply Rogerio though, with the foreach above I will have all the values. However, I wanted only with the pXX index.

  • You can put a condition.. if($numero == "XX") {//salva em lugar pra usar depois ou faça o que quiser}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.