Solved

String vs Array

Posted on 2008-06-23
3
253 Views
Last Modified: 2008-07-05
PHP
Question:
I have bunch code that im using array to store the data.
I was think to change array to string.
how can i do that
as show below is one small part of my code.
how can i change it to string that i can get the same output result

  $query = mysql_query(select * from student);
   
    while($row = mysql_fetch_array($query))
       {
       $this->GetCompNumberReturn[$i] = $row['COMPNUMBER'];
        $i++;
                       }
0
Comment
Question by:firekiller15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
binarydesignnz earned 250 total points
ID: 21852528
Is this something like what you want?
<?php
 
 
if($query = mysql_query(select * from student)){
    
    $output = "";
    $seperator = "\n"
 
    while($row = mysql_fetch_array($query)){
        $output .= $row['COMPNUMBER'] .$seperator; 
    }
}  
 
?>

Open in new window

0
 

Author Comment

by:firekiller15
ID: 21852815
the $row['COMPNUMBER'] is assign to $output  as a string?

for example i have 3 record can i out display all the 3 record
say i put code above in function a()
and i make $ouput as object variable
then i create a function called function b()
in function b i do this
echo $this->output can the output display all the 3 record in function b?


 
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 21852839
If you want to save the array as a string so that you can save it, you can serialize it:

 $myarray = array('item'=>'value', 'item2'=>'value');
 $mystring = serialize($myarray);
 echo "Your array looks like this serialized: $mystring<br />";
 $myarray_again = unserialize($mystring);
 echo "If we bring it back to an array, we can print_r: <br />";
 print_r($myarray_again);
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question