Jump to content

Array format


timmah1

Recommended Posts

I have my array like so

$inaque = array("'$dir'"=>"'$company'");

 

When I run

print_r($inaque);

 

It shows like

Array ( ['share_what_you_want'] => 'Share What You Want' )

 

How can I get this array to print out like

array ( 'share_what_you_want' => 'Share What You Want' )

 

Without the [ ]

 

This is the format that is needed for this code that has already been written by somebody else.

 

Thanks in advance

Link to comment
Share on other sites

that's just what print_r does, I can't fathom why anyone would write code to check what print_r outputs rather than just checking against the original array, that's just crazy.  You're either going to have to pass the print_r result to a sting and then do a regular expression replace on it, or can the code that was written by a crazy person and find something sane to do the job.

Link to comment
Share on other sites

Thank you seanlim, it's what we needed.

 

Now, I am still learning about arrays, so I know some of my questions may be minor.

 

This is only pulling one from the database, when in fact, there is 2 right now, but the array is only showing one.

 

How can I put all of the values into the array?

include($_SERVER['DOCUMENT_ROOT']."/inc/config.db.php");
            $path = $_SERVER['DOCUMENT_ROOT']."/panel/testing/connectors/sample/projects/";
                            
                    foreach(glob($path . '*', GLOB_ONLYDIR) as $dir) {
                        $dir = basename($dir);
                        //echo $dir."<br />";
                                    
                        $companyName = "SELECT * FROM app_queue WHERE company LIKE '%$dir%' AND status = '1'";
                        $compResult = mysql_query($companyName);
                              
                            while($getComp = mysql_fetch_array($compResult)){
                                $status = $getComp['status'];
                                $company = $getComp['company'];
                            
                                    $inaque = array($dir=>$company);                                    
                            }
                                                    
                    };
                    return $inaque;

Link to comment
Share on other sites

This is the format that is needed for this code that has already been written by somebody else.

 

I can just about bet that the code is expecting an actual php array variable with specific key/value pairs. Not the print-out/print_r/var_dump/var_export (which was already suggested in your previous thread on this) of an array and not a string that looks like an array.

 

What is this code you are trying to supply data to?

Link to comment
Share on other sites

This is the format that is needed for this code that has already been written by somebody else.

What is this code you are trying to supply data to?

 

It's for building apps dynamically. Right now, we build them manually, what this code does is

 

Scans a directory, checks the db for a company name that matches the $dir variable, then puts items into the array.

 

That part works fine now, the problem I'm having now is that the array is only populated with 1 item, and the array should show all items.

Right now, there are 2 in thh db with a status of 1, but the array is only pulling 1 of them

Link to comment
Share on other sites

I bet you are getting the last data?

 

$inaque = array($dir=>$company);

 

^^^ That line of code overwrites the $inaque variable on each iteration of the loop. You only end up with the last set of data after the end of the loop. If your goal (which you haven't actually shown) is to build an array of arrays, you would use -

 

$inaque[] = array($dir=>$company);

Link to comment
Share on other sites

ok, I'm obviously lost.

 

I need t query the db with each $dir variable, and then return the result.

I can query the db and pull exactly what I need with one $dir, but I have no idea how to query the db foreach $dir variable.

 

This is the code, can somebody please help me out here?

<?php

include($_SERVER['DOCUMENT_ROOT']."/inc/config.db.php");
            $path = $_SERVER['DOCUMENT_ROOT']."/panel/testing/connectors/sample/projects/";
                            
                    foreach(glob($path . '*', GLOB_ONLYDIR) as $dir) {
                        $dir = basename($dir);
                        //echo $dir."<br />";
                                    
                        $companyName = "SELECT * FROM app_queue WHERE company LIKE '%$dir%' AND status = '1'";
                        $compResult = mysql_query($companyName);
                              
                            while($getComp = mysql_fetch_array($compResult)){
                                $status = $getComp['status'];
                                $company = $getComp['company'];
                            
                                    $inaque = array($dir=>$company);                                    
                            }
                                                    
                    };
                    return $inaque;

?>

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.