Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Array declaration help.
Old 04-17-2009, 07:20 PM Array declaration help.
Webmaster Talker

Posts: 626
Trades: 0
I need to know if the following two statements will accomplish the same thing:

Code:
$installdefs["Mortgages"][][]["from"] = '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php';
Code:
  'layoutdefs' => 
  array (
	0 => 
	array (
      'from' => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php',
      'to_module' => 'Accounts',
    ),
  ),
);
I know that the second will overwrite the WHOLE array. However, if that was the only thing declared for each would it be the same?

I'm asking because I have additional lines that I need to add to a PHP file. The second one is there already. I need to add more values to the array and I wanted to do it using the first method because the 0 => numbers will be different each time.
jim.thornton is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-18-2009, 12:32 AM Re: Array declaration help.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Your second code segment seems to be incomplete. The first is equivalent to this:

PHP Code:
$installdefs = array("Mortgages" =>array(array(array("from" => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php')))); 
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 04-18-2009, 12:38 AM Re: Array declaration help.
Webmaster Talker

Posts: 626
Trades: 0
Quote:
Originally Posted by JeremyMiller View Post
Your second code segment seems to be incomplete. The first is equivalent to this:

PHP Code:
$installdefs = array("Mortgages" =>array(array(array("from" => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php')))); 
Sorry, I took only a section of the file. Here it is again:
PHP Code:
$installdefs["layoutdefs"][] = array(
     
'from' => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php',
     
'to_module' => 'Accounts',
 );

$installdefs["relationships"][] = array(
      
'meta_data' => '<basepath>/SugarModules/relationships/relationships/accounts_fp__mortgagesMetaData.php',
);

$installdefs["language"][] = array(
    
'from' => '<basepath>/SugarModules/relationships/language/Accounts.php',
    
'to_module' => 'Accounts',
    
'language' => 'en_us',
);

$installdefs["vardefs"][] = array(
    
'from' => '<basepath>/SugarModules/relationships/vardefs/Accounts.php',
    
'to_module' => 'Accounts',
); 
Is that the same as this:
PHP Code:
$installdefs = array (
  
'layoutdefs' => 
  array (
    
=> 
    array (
      
'from' => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php',
      
'to_module' => 'Accounts',
    ),
  ),
  
'relationships' => 
  array (
    
=> array (
      
'meta_data' => '<basepath>/SugarModules/relationships/relationships/accounts_fp__mortgagesMetaData.php',
    ),
  ),
  
'language' => 
  array (
    
=> 
    array (
      
'from' => '<basepath>/SugarModules/relationships/language/Accounts.php',
      
'to_module' => 'Accounts',
      
'language' => 'en_us',
    ),
  ),
  
'vardefs' => 
  array (
    
=>
    array (
      
'from' => '<basepath>/SugarModules/relationships/vardefs/Accounts.php',
      
'to_module' => 'Accounts',
    ),
  ),
); 
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 04-18-2009, 12:44 AM Re: Array declaration help.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
No. It's close, though. Let me teach you how to fish now:

PHP Code:
print '<pre>'.print_r($installdefs,true).'</pre>'
that will display the array itself all prettily-formatted for you. You can then see how things vary or if they are equal.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 04-18-2009, 01:01 AM Re: Array declaration help.
Webmaster Talker

Posts: 626
Trades: 0
I just used the following code to test it and the resulting arrays look identical to me:

PHP Code:
<?php
$installdefs1 
= array (
  
'layoutdefs' => 
  array (
    
=> 
    array (
      
'from' => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php',
      
'to_module' => 'Accounts',
    ),
  ),
  
'relationships' => 
  array (
    
=> array (
      
'meta_data' => '<basepath>/SugarModules/relationships/relationships/accounts_fp__mortgagesMetaData.php',
    ),
  ),
  
'language' => 
  array (
    
=> 
    array (
      
'from' => '<basepath>/SugarModules/relationships/language/Accounts.php',
      
'to_module' => 'Accounts',
      
'language' => 'en_us',
    ),
  ),
  
'vardefs' => 
  array (
    
=>
    array (
      
'from' => '<basepath>/SugarModules/relationships/vardefs/Accounts.php',
      
'to_module' => 'Accounts',
    ),
  ),
);  


$installdefs["layoutdefs"][] = array(
     
'from' => '<basepath>/SugarModules/relationships/layoutdefs/Accounts.php',
     
'to_module' => 'Accounts',
 );

$installdefs["relationships"][] = array(
      
'meta_data' => '<basepath>/SugarModules/relationships/relationships/accounts_fp__mortgagesMetaData.php',
);

$installdefs["language"][] = array(
    
'from' => '<basepath>/SugarModules/relationships/language/Accounts.php',
    
'to_module' => 'Accounts',
    
'language' => 'en_us',
);

$installdefs["vardefs"][] = array(
    
'from' => '<basepath>/SugarModules/relationships/vardefs/Accounts.php',
    
'to_module' => 'Accounts',
);  

echo 
'<pre style="border: 2px solid black; padding: 1em; margin: 20px;>'.print_r(get_defined_vars(),true).'</pre>';
?>

Last edited by jim.thornton; 04-18-2009 at 01:05 AM..
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 04-18-2009, 01:06 AM Re: Array declaration help.
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
They are.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366

Last edited by lizciz; 04-18-2009 at 01:07 AM..
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 04-18-2009, 01:26 AM Re: Array declaration help.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Thanks Mattias. He's right. I thought your second arrays included the very first at in your original post. That one has an additional array of nesting which was missing. The last 2 are equal.

Sorry about that!
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 04-19-2009, 03:03 PM Re: Array declaration help.
Webmaster Talker

Posts: 626
Trades: 0
No worries... Thanks for the help!
jim.thornton is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Array declaration help.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26416 seconds with 12 queries