Jump to content

Question related to arrays and print


g_p_java

Recommended Posts


$all_arrays_in_one = array();
$ar0 = array();
$ar1 = array();
$ar2 = array();
$ar3 = array();

$j = 0;

for($j = 0; $j <= 3 ;$j++) {

      if($j == 0)
              $all_arrays_in_one[$j] = $ar0;   //$ar0 has a string "My"

      if($j == 1)
              $all_arrays_in_one[$j] = $ar1;  // $ar1 "name"


      if($j == 2)
              $all_arrays_in_one[$j] = $ar2;  //$ar2 "is"

      if($j == 3)
              $all_arrays_in_one[$j] = $ar3;   //$ar3 "g_p"

} //for

var_dump($all_arrays_in_one);

//it prints all the the elements

//i then do 

print implode(" ",$all_arrays_in_one);

//add a space
//Then i would like to output in the page using echo "My name is g_p"

 

The problem is that print implode(" ",$all_arrays_in_one); doesn't print "My name is g_p"

 

What shall i do?

 

Thanks

Link to comment
Share on other sites

You never assign the strings 'My' 'name' 'is' 'g_p' to anything.

 

What exactly is the point of your code?

 

I would like to take the values of an array and not the keys and implode them.

Usually the examples i have seen are :

 


<?php

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

echo $comma_separated; // lastname,email,phone

?>


 

The difference is that in my code, when i do vardump i get :

 

In my example here i have an array which consists of {key = id, key = ga,key =  ajf,key =  bbd }

 

array(4) { [0]=>  array(2) { [0]=>  string(1) "i" [1]=>  string(1) "d" } [1]=>  array(2) { [0]=>  string(1) "g" [1]=>  string(1) "a" } [2]=>  array(3) { [0]=>  string(1) "a" [1]=>  string(1) "j" [2]=>  string(1) "f" } [3]=>  array(3) { [0]=>  string(1) "b" [1]=>  string(1) "b" [2]=>  string(1) "d" } }

 

Also i did that: $implodedArray = implode(" ",$all_arrays_in_one);

print $implodedArray;  but i get that error :

 

Warning: implode() [function.implode]: Invalid arguments passed in

 

Link to comment
Share on other sites

What does....

[code=php:0]
echo "<pre>';
print_r($all_arrays_in_one);
echo "</pre>";

 

display?

 

Well i need to display what $all_arrays_in_one outputs: e.g. adjikl , to print a whole string

I mean not like this    * =>  string(1) "b" [1]=>  string(1) "b" [2]=>  string(1) "d" } } etc

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.