Function explodes() into a vector

Asked

Viewed 213 times

2

I get a variable that way:

$VAR = "joao.silva/jose.ferreira/maria.jose/carlos.eduardo/";

and I need to store it this way:

$VET = array('joao.silva', 'jose.ferreira', 'maria.jose', 'carlos.eduardo');

Someone could help me manipulate that information to save it that way?

  • 1

    I do not understand what is your difficulty, the function explodes that indicated returns the result you want. Just use explode("/", $string_a_manipulate);

  • @lazyFox there is no problem in answering the question explaining the use of the function explodes, including ha my view none of the answers below effectively answers Rafael’s question, the question even this bad formulated.... starting that this is not an accepted php variable: $VAR = joao.silva/jose.ferreira/maria.jose/carlos.eduardo/

  • Do not blame your misinterpretation on the author, so much so that the doubt has already been solved and posted :)

3 answers

5


<?php

$VAR = "joao.silva/jose.ferreira/maria.jose/carlos.eduardo/";

// assim você vai ter no arr_nomes todas as ocorrências
$arr_nomes = explode("/",$VAR);

//mostra todos os dados do array
print_r($arr_nomes);

/*
SAÍDA
Array ( [0] => joao.silva [1] => jose.ferreira [2] => maria.jose [3] => carlos.eduardo [4] => ) Nome: joao.silva 

*/

//realiza a leitura de todos os itens do array
foreach($arr_nomes as $nome){

    echo "Nome: $nome </br>"    ;
}

/* SAÍDA 
Nome: jose.ferreira 
Nome: maria.jose 
Nome: carlos.eduardo 
Nome: 
*/
/** Observar que seu delimitador para separação de itens é a "/", 
  então seu último item do array vai estar vazio **/
  • BALL SHOW! thank you very much.

3

   $VAR = joao.silva/jose.ferreira/maria.jose/carlos.eduardo/
   $pieces = explode("/", $VAR);
    echo $piece[0]; //joao.silva

See if it solves ^^

2

Use like this $vet = explode("/", $var);

More here

  • 2

    There is nothing wrong with sharing links, but if possible, pull the information you would like to pass on to the boy who asked, to the network, so if any (difficult but not impossible) php.net/manual dies, the answer will not become obsolete.

Browser other questions tagged

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