We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    Hello,

    I was wondering whether somebody could give me a little hand on the following php code - I guess there is a better way to do what I want.

    I have an array with some ticker symbols. since not all ticker symbols are available at yahoo.com but at yahoo.de I need to assign the country to the symbol - the symbols are grouped by markets.

    the code below is working - I was just wondering whether there is a better way to do it. thank you in advance for your help.

    // multi indices by market
    $symbols = array(
    	// yahoo.de
    	'de' => array(
    		'eu' => array('^ATX','^BFX','^FCHI','^GDAXI','^AEX','^OSEAX','^MIBTEL','^SMSI','^OMXSPI','^SSMI','^SSHI','^FTSE')
    	),
    	// yahoo.com
    	'us' => array(
    		'am' => array('^MERV','^BVSP','^GSPTSE','^MXX','^GSPC'),
    		'ap' => array('^AORD','^SSEC','^HSI','^BSESN','^JKSE','^KLSE','^N225','^NZ50','^STI','^KS11','^TWII'),
    		'af'	=> array('^CCSI','^TA100'),
    		'dj'	=> array('^DJA','^DJI','^DJT','^DJU'),
    		'ny'	=> array('^NYA','^NIN','^NTM','^NUS','^NWL','^TV.N'),
    		'na'	=> array('^IXBK','^NBI','^IXIC','^IXK','^IXF','^IXID','^IXIS','^IXQ','^IXFN','^IXUT','^IXTR','^NDX','^TV.O'),	
    		'sp'	=> array('^OEX','^MID','^GSPC','^SPSUPX','^SML'),
    		'ou'	=> array('^XAX','^IIX','^NWX','^PSE','^DWC','^XMI','^SOXX','^DOT','^RUI','^RUT','^RUA'),
    		'tr'	=> array('^TNX','^IRX','^TYX','^FVX'),
    		'co'	=> array('CRU07.NYB','^DJS2','^DJC','GIU07.CME','^XAU','RCIV10.CME'),
    		'fu'	=> array('DJU07.CBT','NVU07.CME','ESU07.CME','YMU07.CBT','NQU07.CME','SPU07.CME')
    	)
    );
    
    
    $data = array();
    
    foreach($symbols as $s => $region) {
    
    	foreach($region as $r => $market) {
    		$array = array();
    	
    		foreach($market as $m => $ticker) {			
    			//$data[$i] = array($d,$m);
    			array_push($array, array($ticker,$s));
    			//echo $r."\n";
    		};
    		$data[$r] = $array;
    		
    	};
    	
    };
    
    foreach($data['eu'] as $key => $v) {
    	$html .= 'ticker: '.$v[0].' market: '.$v[1]. '<br />';
    };
    echo $html;
      • 19889
      • 616 Posts
      thanks for replying - as for now, I’d like to stick to just having them in the array as mysql is way beyond my skills - I was just wondering whether the foreach stuff could be done easier.

      thanks again