Make a new multi dimensional array from the existing array in smarty - smarty

My whole moto in this question is to make a new array from existing array and to reverse the first and second index of array.
I have an array
Array
(
[0] => Array
(
[0] => Array
(
[field] => Array
(
[name] => name
[tabindex] => 0
)
[colspan] => 3
)
)
[1] => Array
(
[0] => Array
(
[field] => Array
(
[name] => sequence
[tabindex] => 0
)
[colspan] => 3
)
)
[2] => Array
(
[0] => Array
(
[field] => Array
(
[name] => description
[tabindex] => 0
)
[colspan] => 3
)
)
[3] => Array
(
[0] => Array
(
[field] => Array
(
[name] => status
[tabindex] => 0
)
[colspan] => 3
)
)
[4] => Array
(
[0] => Array
(
[field] => Array
(
[name] => modified_by_name
[customCode] => {$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}
[label] => LBL_DATE_MODIFIED
[tabindex] => 0
)
[colspan] => 3
)
)
[5] => Array
(
[0] => Array
(
[field] => Array
(
[name] => created_by_name
[customCode] => {$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}
[label] => LBL_DATE_ENTERED
[tabindex] => 0
)
[colspan] => 3
)
)
[6] => Array
(
[0] => Array
(
[field] => Array
(
[name] =>
)
)
[1] => Array
(
[field] => Array
(
[name] =>
)
)
)
)
Now i have to make a new array with first index on second and second on first index like this But have to do only in smarty not in php etc
Array
(
[0] => Array
(
[0] => Array
(
[field] => Array
(
[name] => name
[tabindex] => 0
)
[colspan] => 3
)
[1] => Array
(
[field] => Array
(
[name] => sequence
[tabindex] => 0
)
[colspan] => 3
)
[2] => Array
(
[field] => Array
(
[name] => description
[tabindex] => 0
)
[colspan] => 3
)
[3] => Array
(
[field] => Array
(
[name] => status
[tabindex] => 0
)
[colspan] => 3
)
[4] => Array
(
[field] => Array
(
[name] => modified_by_name
[customCode] => {$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}
[label] => LBL_DATE_MODIFIED
[tabindex] => 0
)
[colspan] => 3
)
[5] => Array
(
[field] => Array
(
[name] => created_by_name
[customCode] => {$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}
[label] => LBL_DATE_ENTERED
[tabindex] => 0
)
[colspan] => 3
)
)
)

I think the following might help you.
You could loop the array you have and fill a new array with the values. Lets call the original $firstArray and the new one $newArray. I see that the first item from the subarrays are what you need(and there are no other items apart from 0) so you could do the following:
{$newArray = []}
{foreach $firstArray as $item}
{$newArray[] = $item.0}
{/foreach}
$item.0 selects the first subarray(there are no other). You might have to use $item[0] depending on your smarty version.
If there is more than 1 subarray, then loop $items first before you add an array to the $newArray.
It looks as if there's another array encapsuling your firstArray, so perhaps you need to select the subarray from the main one first....
note: I used smarty 3. Perhaps you use a different version, be sure to check the syntax for your version.

Related

i got this array from laravel controller now how to print this in laravel blade. because here is an array and inside this there is another array

Array (
[0] => Array ( [JobId] => 5990027 [DeliveryDate] => 2018-07-18T13:42:54)
[1] => Array ( [JobId] => 5990042 [DeliveryDate] => 2018-07-18T12:51:53.483 )
[2] => Array ( [JobId] => 5990043 [DeliveryDate] => 2018-07-18T12:51:53.51 )
[3] => Array ( [JobId] => 5990060 [DeliveryDate] => 2018-07-18T12:56:11 )
[4] => Array ( [JobId] => 5990101 [DeliveryDate] => 2018-07-18T13:05:57 )
[5] => Array ( [JobId] => 5990102 [DeliveryDate] => 2018-07-18T13:08:42 )
[6] => Array ( [JobId] => 5990109 [DeliveryDate] => 2018-07-18T13:05:12 )
[7] => Array ( [JobId] => 5990115 [DeliveryDate] => 2018-07-18T13:07:54 )
[8] => Array ( [JobId] => 5990116 [DeliveryDate] => 2018-07-18T13:05:31 )
[9] => Array ( [JobId] => 5990117 [DeliveryDate] => 2018-07-18T13:04:59 )
[10] => Array ( [JobId] => 5990118 [DeliveryDate] => 2018-07-18T13:07:18 )
)
You'll want to read up on loops in Blade templates. Here's the official documentation. Perhaps foreach will do what you want, then just loop through them and follow the examples to see how you can reference that particular element as output.

converting array to stdClass

I am getting the result below. i want to print the question and cat_id but don't know how??? Actually i'm new in codeigniter. Any help will be appreciated .
Array
(
[data] => Array
(
[0] => Array
(
[records] => Array
(
[0] => stdClass Object
(
[qst_id] => 1
[question] => Describe a major change that occurred in a job that you held. How did you adapt to this change?
[cat_id] => 1
)
[1] => stdClass Object
(
[qst_id] => 2
[question] => Tell about a situation in which you had to adjust to changes over which you had no control. How did you handle it?
[cat_id] => 1
)
)
[cat_id] => 1
)
[1] => Array
(
[records] => Array
(
)
[cat_id] => 4
)
[2] => Array
(
[records] => Array
(
[0] => stdClass Object
(
[qst_id] => 3
[question] => Give an example of a situation where others were intense but you were able to maintain your composure.
[cat_id] => 6
)
)
[cat_id] => 6
)
)
)

Elasticsearch bool filter query return results

I have an index with mappings:
[test] => Array
(
[mappings] => Array
(
[testype] => Array
(
[properties] => Array
(
[brand_id] => Array
(
[type] => integer
)
[color] => Array
(
[type] => string
[index] => not_analyzed
)
[description] => Array
(
[type] => string
)
[discount] => Array
(
[type] => float
)
[newprice] => Array
(
[type] => float
)
[oldprice] => Array
(
[type] => float
)
[sex] => Array
(
[type] => string
[index] => not_analyzed
)
[store_id] => Array
(
[type] => integer
)
[title] => Array
(
[type] => string
)
)
)
)
)
And trying to filter my data with this query:
Array
(
[index] => test
[type] => testype
[size] => 100
[body] => Array
(
[query] => Array
(
[filtered] => Array
(
[filter] => Array
(
[bool] => Array
(
[must] => Array
(
[term] => Array
(
[brand_id] => 53
[color] => red
)
)
)
)
)
)
)
)
Expecting to get result like SELECT ... WHERE brand_id=53 AND color=red, but have results like brand_id=53 OR color=red. Am i'm missing something?
Actualy, i want to have a filter like SELECT ... WHERE aaaa='a' AND bbbb='b' AND cccc IN (1,2,6,9) AND ddd IN (xxx,yyy)
You have to put the terms in different arrays.
Disclaimer: I guess this syntax is the PHP one, I'm not familiar with it, please forgive any syntax error.
Try this:
[must] => Array
(
[term] => Array
(
[brand_id] => 53
)
[term] => Array
(
[color] => red
)
)
Your last query should look like this:
[must] => Array
(
[term] => Array
(
[aaaa] => 'a'
)
[term] => Array
(
[bbbb] => 'b'
)
[terms] => Array
(
[cccc] => Array(1, 2, 6, 9)
[minimum_should_match] => 1
)
[terms] => Array
(
[dddd] => Array('xxx', 'yyy')
[minimum_should_match] => 1
)
)

How to convert from newsoap to xml using simplexelement,simple_to_string

error_reporting(0);
session_start();
$link=$_POST['Host'];
$_SESSION['Host']=$link;
$client = new SoapClient("http://".$link."/api/soap/?wsdl");
/*api credentials*/
$apiuser=$_POST['User'];
$_SESSION['User']=$apiuser;
$apikey =$_POST['Key'];
$_SESSION['Key']=$apikey;
/*Action to be made */
$action =$_POST['Catalog'];
$_SESSION['Catalog']=$action;
/*Error trapping if in case number will be input*/
if(ctype_alpha(!$action))
{
die('Incorrect format');
}
else
{
$sess_id= $client->login($apiuser, $apikey);
/api login/
echo"Total Active list Product:".(count($client->call($sess_id, $action)));
echo"";
print_r($result=$client->call($sess_id,$action));
echo"";
}
?>
Array
(
[0] => Array
(
[product_id] => 1
[sku] => ROx12345
[name] => acer netbook
[set] => 4
[type] => simple
[category_ids] => Array
(
)
[website_ids] => Array
(
[0] => 1
)
)
[1] => Array
(
[product_id] => 2
[sku] => Cats1234
[name] => starbucks mug
[set] => 4
[type] => simple
[category_ids] => Array
(
)
[website_ids] => Array
(
[0] => 1
)
)
[2] => Array
(
[product_id] => 3
[sku] => samsung2141
[name] => samsung 3110
[set] => 4
[type] => grouped
[category_ids] => Array
(
)
[website_ids] => Array
(
[0] => 1
)
)

Is it possible to get a value from view.yml in an action

I'm wondering if it's possible to get the name of a stylesheet from view.yml in an action, ideally using something as simple as:
sfConfig::get('......');
I'd like to access the existing declaration in view.yml instead of hardcoding it or duplicating it somewhere like app.yml.
Thanks.
If you want to access the current Module's Config, you can use:
sfViewConfigHandler::getConfiguration(array(dirname(__DIR__) . '/config/view.yml'));
It should return something like this:
Array
(
[indexSuccess] => Array
(
[javascripts] => Array
(
[0] => mission-control.js
)
[stylesheets] => Array
(
[0] => control-box.css
[1] => question.css
)
)
[newSuccess] => Array
(
[javascripts] => Array
(
[0] => box-checker.js
[1] => topic.js
)
[stylesheets] => Array
(
[0] => question.css
[1] => topic.css
)
)
[searchSuccess] => Array
(
[javascripts] => Array
(
[0] => topic.js
)
[stylesheets] => Array
(
[0] => topic.css
)
)
[showSuccess] => Array
(
[javascripts] => Array
(
[0] => mission-control.js
)
[stylesheets] => Array
(
[0] => control-box.css
[1] => question.css
)
)
[editSuccess] => Array
(
[javascripts] => Array
(
[0] => box-checker.js
[1] => topic.js
)
[stylesheets] => Array
(
[0] => question.css
[1] => topic.css
)
)
[all] => Array
(
[stylesheets] => Array
(
)
[javascripts] => Array
(
)
)
)

Resources