Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Rozbicie tablicy na stringi
bliitz
post
Post #1





Grupa: Zarejestrowani
Postów: 155
Pomógł: 12
Dołączył: 5.04.2008

Ostrzeżenie: (0%)
-----


Witam

Załóżmy, że przykładowa tablica wygląda tak:

  1. $conditions = array( 'required', 'numeric' );


W jaki sposób można ją rozbić aby otrzymać dwa stringi, tak aby w każdym znajdowała się jedna wartość z tablicy?

Coś w ten deseń:

  1. $string1 = 'required';
  2. $string2 = 'numeric';


implode zwraca niestety jeden string, a mi są potrzebne oddzielne.

Ten post edytował bliitz 13.01.2010, 14:23:20
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
bliitz
post
Post #2





Grupa: Zarejestrowani
Postów: 155
Pomógł: 12
Dołączył: 5.04.2008

Ostrzeżenie: (0%)
-----


Cytat(ddiceman @ 13.01.2010, 14:47:24 ) *
no ale jak juz cos, to (za skarby nie moge wymyslec, po co (IMG:style_emoticons/default/smile.gif) ) rozwiazaniem dla Ciebie sa tzw. "zmienne zmienne"


już piszę po co (IMG:style_emoticons/default/rolleyes.gif) , mam taką metodę
  1. /**
  2.   *
  3.   * @param array $post
  4.   * @param array $conditions
  5.   * @return boolean
  6.   */
  7. public function check( $post, array $conditions )
  8. {
  9. $this->post = $post;
  10. $this->conditions = new Validation( $this->post );
  11. $this->conditions->pre_filter( 'trim' );
  12. foreach( $conditions as $k => $v )
  13. {
  14. $this->conditions->add_rules( $k, $v );
  15. }
  16. return $this->conditions->validate();
  17. }


i wywołuje ją w następujący sposób

  1. Parse_Data::instance()->check( $_POST, array( 'queue' => array( 'required', 'numeric' ),
  2. 'spots' => 'required',
  3. 'score' => 'required',
  4. 'lost_spots' => 'required',
  5. 'name' => 'required' ) )


w tym momencie jest błąd, gdyż zamiast postaci:

  1. add_rules( queue, required, numeric );

jest
  1. add_rules( queue, array( required, numeric ) );
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 4.10.2025 - 23:20